A Program to Check Armstrong Number
In this example, we are giving a program to check whether an n-digit integer is an Armstrong number or not. An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.
Program to check Armstrong number:
# Check Armstrong number
num = int(input('Enter a number: '))
order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else :
print(num,"is not an Armstrong number")
Output:
Enter a number: 153 153 is an Armstrong number Enter a number: 737 737 is not an Armstrong number