Skip to content
Home » Program to check if a given number is an Armstrong number or not in Python

Program to check if a given number is an Armstrong number or not in Python

Below is the python code to check if a given number is an Armstrong number or not

If a 3 digit number is equal to the sum of the cubes of its each digit, then it is an Armstrong Number.

num=int(input("Enter a 3 digit number:"))
summ=0
temp=num
while (temp>0):
    digit=temp%10
    summ+=digit**3
    temp//=10
if (num==summ):
    print(num,"is an Armstrong number")
else:
    print(num,"is not an Armstrong number")

Output

Enter a 3 digit number:456

456 is not an Armstrong number