Python Program to check whether a given number is Armstrong or not
2 min readApr 5, 2021
Program to check whether a given number is Armstrong or not
A number is said to be an Armstrong if the sum of each digit’s cube of a given number equals the original number.
Example:
Given number 153 1*1*1 + 5*5*5 + 3*3*3 = 153 So the given number is Armstrong.
The following is a source code to detect Armstrong number in Python:
#Program to a given number is Armstrong
#Take user input
number = int(input(“Enter the number:”))
#Initialize sum
sum = 0
#Compute the sum of cube of each digit
temp = number
while(temp > 0):
digit = temp%10
sum += digit**3
temp //= 10
#Check the result
if number == sum:
print(number, “is an Armstrong number.”)
else:
print(number, “is not an Armstrong number.”)