Write a Program in Python to find Armstrong numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# Python program to check if the number is an Armstrong number or not # take input from the user num = int(input("Please Enter a number: ")) # initialize Result Result = 0 # this code will find the Result of the cube of each digit T4Tutorials = num while T4Tutorials
> 0: digit = T4Tutorials % 10 Result += digit ** 3 T4Tutorials //= 10 # Show the result if num == Result: print("Congaratulations! ", num,"is an Armstrong number") else: print("Sorry! ",num,"is not an Armstrong number") |
Output
Please Enter a number: 5
Sorry! 5 is not an Armstrong number