1 – Best Python program to check Armstrong Number

Python program to check Armstrong number

Python program to check Armstrong number : For a given number if the sum of digits each raised to the power of number of digits then the it is Armstrong number. E.g. 1634 = (1*1*1*1)+(6*6*6*6)+(3*3*3*3)+(4*4*4*4) Total number of digits n = 4 Hence we have to calculate 14 + 64 + 34 + 44

Logic to check Armstrong number in python

`"""Author : ITVoyagers (https://itvoyagers.in)Date :08th August 2018Description : Python program to check if the number provided by the user is an Armstrong number or not."""# take input from the usernum = int(input("Enter any number: "))power=len(str(num))# initialize sumsum = 0# find the sum of the cube of each digittemp = numwhile temp > 0:    digit = temp % 10    sum += digit ** power    temp //= 10# display the resultif num == sum:    print(num,"is an Armstrong number")else:    print(num,"is not an Armstrong number")`

Output :

Enter any number: 371
371 is an Armstrong number
>>> ================================
Enter any number: 1634
1634 is an Armstrong number
>>> ================================
Enter any number: 121
121 is not an Armstrong number