Python Program to check number is Armstrong or not


In this program, You will learn how to check number is Armstrong or not in Python.


Some list are: 153 370 371 407

Example: How to check number is Armstrong or not in Python.

n = int(input("Enter a number:"))

num = n
rev = 0

while n > 0:
    r = n % 10
    rev = rev + r * r * r
    n = int(n / 10)

if rev == num:
    print("Number is Armstrong:", num)
else:
    print("Number is not Armstrong:", num)

Output:

Enter a number:153
Number is Armstrong: 153