Armstrong Number Program in Python

Python program to check weather a number is Armstrong number or not.

What is Armstrong Number?

If the sum of cube of each digit of a 3 digit number is the number itself then such numbers are called Armstrong number.

For example 153 is a armstrong because sum of cube of 1, 5, 3 is 153 itself.

13+53+33 = 153.

Armstrong Number Program in Python

Write a program in python to check weather a number is armstrong number or not.

# Python program to check if the number is Armstrong number or not

num = int(input("Enter the Number\n"))
sum = 0
temp = num

while (temp > 0):
    d = temp%10
    sum = sum+d**3
    temp = temp//10

if (sum == num):
    print("The Number is an Armstrong Number")
else:
    print("The Number is Not an Armstrong Number")

Output:

Enter the Number
370
The Number is an Armstrong Number

Leave a Reply