Python Program for Finding Armstrong Number

Python Program for Finding Armstrong Number. A number is termed Armstrong number if it’s up to the total of the cubes of its own digits.

Lets take an Example:

153 = (1*1*1) + (5*5*5) + (3*3*3) = 153
1634 = (1*1*1*1) + (6*6*6*6) + (3*3*3*3) + (4*4*4*4) = 1634

In the above 153 and 1634 is Armstrong number because it digit cubes is total of itself.

To understand this example, you should have knowledge of following Python programming topics:

Source Code For Finding Armstrong Number of n digits in Python

# Armstrong Number in Python

num = int(input("Enter a number:"))
sum=0
temp = num

n = len(str(num))
  
while temp > 0:
    digit = temp % 10
    sum += digit ** n
    temp //= 10
if sum == num:
    print(num,'is Armstrong Number')
else:
    print(num,'is not Armstrong Number')

It’s also available on GitHub – https://github.com/studygyaan/python-tutorial/blob/master/Python-Armstrong.py