Armstrong number is a number that is equal to the sum of cubes of its digits.
Example:
370 = 3*3*3 + 7*7*7 + 0*0*0 => 370 is an Armstrong number.
Python program to check if the number is an Armstrong Number or not. If you don't have knowledge of the below topics, please go through the topics before continue to this,
# To check if a number is Armstrong Number or not
number = int(input("Enter a number to check : "))
i = 0
temp = number
while temp > 0:
digit = temp % 10
i += digit ** 3
temp //= 10
# Print result
if number == i:
print(number, "is an Armstrong number")
else:
print(number, "is not an Armstrong number")
Output:
Enter a number to check : 370
370 is an Armstrong number
Enter a number to check : 125
125 is not an Armstrong number
Enter a number to check : 153
153 is an Armstrong number
Comments (0)