61. Python Program to find the given number is Armstrong number or Not.
How does this program work?
- In this program you are going to learn about to check if a number is Armstrong number or not using Python.
- An Armstrong number is a number whose value is equal to the sum of the cubes of its digits.
- If sum is equal to the original number, then that number is armstrong number else the number is not a armstrong number.
Here is the code
n = int(input("Enter a number: "))
a = 0
temp = n
while temp > 0:
b = temp % 10
a += b ** 3 #(a = a + (b*b*b))
temp //= 10 #(temp = int(temp/10))
if n == a:
print(n,"is an Armstrong number")
else:
print(n,"is not an Armstrong number")