🐍Python Program #21: Check Armstrong Number | Python Programming

Опубликовано: 30 Апрель 2026
на канале: All In Graphics
46
2

🐍Python Program #21: Check Armstrong Number | Python Programming

💡 What is an Armstrong number? It's a number that equals the sum of its digits
raised to the power of the number of digits. For example, 153 → 1³+5³+3³ = 153 ✔

In this beginner-friendly tutorial, we’ll learn:
✅ The logic behind Armstrong numbers
✅ How to use loops, modulus and power operators
✅ Step-by-step Armstrong number program in Python

Perfect for practice, exams, and coding interviews!

#Python #ArmstrongNumber #PythonForBeginners #PythonPrograms #PythonPractice #CodingForBeginners #computerprogramming #all

Logic:
1. An Armstrong number is a number that is equal to the sum of its own digits raised to the power of the number of digits.
Example: 153
→ Digits: 1, 5, 3 → 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ✔
2. Ask the user to enter a number.
3. Convert the number into string (to count digits easily).
4. Count how many digits are there → n = len(str(num)).
5. Extract digits one by one:
→ Use modulus % 10 to get last digit.
→ Raise it to the power n, add to sum.
6. Remove last digit using // 10 and repeat until num == 0.
7. Compare the sum with the original number.
→ If equal → Armstrong number
→ Else → Not Armstrong


Code:
num = 153
original = num
n = len(str(num))
result = 0

while num != 0:
digit = num % 10
result += digit ** n
num //= 10

if result == original:
print(f"{original} is an Armstrong number")
else:
print(f"{original} is NOT an Armstrong number")


👉 Perfect for Python beginners and school/college projects!

📌 More Python Tutorials (Subscribe to stay updated!):
👉 Python in 5 Minutes: Super Fast Beginner Guide
   • Python in 5 Minutes: Super Fast Beginner G...  
👉 Python Variables and Data Types | Explained in 3 minutes with Examples | Python for Beginners
   • Python Variables and Data Types | Explaine...  
👉 Master Python Loops (For loop & While loop) in Just 5 Minutes | Python For Beginners
   • Master Python Loops (For loop & While loop...  
💻Coding Python Calculator Program 🧮🐍
   • 💻Coding Python Calculator Program 🧮🐍  
👉 How to Check If List is Empty in Python 🐍💻
   • How to Check If List is Empty in Python 🐍💻  
👉 How to Reverse a String in Python Like a Pro!
   • How to Reverse a String in Python Like a Pro!  
👉 Python Lists | 5 Cool Tricks of Lists in Python - You must know!
   • 5 Cool Tricks To Use Lists in Python - You...  
👉3 Ways to Reverse a String in Python — No Slicing! | Python for beginners
   • 3 Ways to Reverse a String in Python — No ...  
👉 Python Programs | Python Programming - Playlist for logic building and practice
   • Python Programs | Python Programming - Pla...  

💡 If this helped you, don’t forget to Like 👍, 💬Drop a comment and
🔔Subscribe for more Python tutorials every week!

#Python #PythonForBeginners #PythonProjects #BeginnerPython #PythonLogic #computerprogramming #pythonprogramming #armstrong #armstrongnumber #pythonprograms