Write a Python Program to check armstrong number of n digits

Write a Python Program to check armstrong number of n digits

Program

def myfun(): 
    num = int(input("Enter Number : "))
    order = len(str(num))
    # initialize sum
    sum = 0
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
        digit = temp % 10
        sum += digit ** order
        temp //= 10
    if num == sum:
        print(num,"is an Armstrong number")
    else:
        print(num,"is not an Armstrong number")
                
if __name__=="__main__":
    myfun()



Output:

Enter Number : 1224
1224 is not an Armstrong number

Input: 120
Output: No
120 is not a Armstrong number.
1*1*1 + 2*2*2 + 0*0*0 = 9

Input: 1253
Output: No
1253 is not a Armstrong Number
1*1*1*1 + 2*2*2*2 + 5*5*5*5 + 3*3*3*3 = 723

Input: 1634
Output: Yes
1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634


More Questions


29 . Write a Python Program to check armstrong number of n digits
30 . Write a program to check armstrong numbers in certain interval
31 . Write a program to merging dictionaries
32 . Write a program to print swapping variables
33 . Write a python program to counting item occurrences
34 . Write a python program to print flatten a nested list
35 . Write a python program to Find the index of the largest number in the list
36 . Write a python program to Find the index of the smallest number in the list
37 . Write a python program to find absolute value of a number in the list
38 . Write a python program to adding a thousand separator
39 . Write a python program startswith and Endswith Methods