🚀 Day 34/150 – Armstrong Number in Python
An Armstrong number is a number that is equal to the sum of its own digits raised to the power of total digits.
Example: 153 = 1³ + 5³ + 3³ = 153
Let’s explore different ways to check Armstrong number in Python 👇
🔹 Method 1 – Using while Loop
n = 153 temp = n digits = len(str(n)) total = 0 while n > 0: digit = n % 10 total += digit ** digits n //= 10 if temp == total: print("Armstrong Number") else: print("Not Armstrong Number")
✅ Best numeric method.
🔹 Method 2 – Taking User Input
✅ Useful for dynamic programs.
🔹 Method 3 – Using for Loop + String
n = 153 digits = len(str(n)) total = sum(int(i) ** digits for i in str(n)) if n == total: print("Armstrong Number") else: print("Not Armstrong Number")
✅ Short and clean method.
🔹 Method 4 – Using Function
def is_armstrong(n): digits = len(str(n)) total = sum(int(i) ** digits for i in str(n)) return n == total print(is_armstrong(153))
✅ Reusable for projects.
📌 Example Output
For 153
Armstrong Number
🎯 Best Method?
✔ while loop → best for logic building
✔ for loop + string → shortest method
✔ function → reusable and clean


