Python Program to Check Given Number Is Armstrong Or Not

Python Program to Check Given Number Is Armstrong Or Not

Example

def Armstrong(N):
    digits = len(str(N))
    addition=0
    temp=N
    while(N>0):
        D = int(N%10)
        addition = addition + (D**digits)
        N = int(N/10)
    
    if (temp==addition):
        print(temp, 'is an Armstrong number')
    else:
        print(temp, 'is not an Armstrong number')

# n = int(input("Enter Number: "))
n=407
Armstrong(n)

Output:

407 is an Armstrong number

Leave a comment