Armstrong Number in Python
In this program, you will get the example code to Check Armstrong Number in Python programming.
Armstrong number is a number which is equal to the sum of the cubes of its individual digits.
For example:-
153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153.
Let’s implement the python program to check Armstrong number using if-else and while loop.
Program code for Armstrong Number in Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #Python Program to Check Armstrong Number num = int(input("Enter a number: ")) sum = 0 # find the sum of the cube of each digit temp = num while temp > 0: digit = temp % 10 sum += digit ** 3 temp //= 10 # print result if num == sum: print(num,"is an Armstrong number") else: print(num,"is not an Armstrong number") |
Output 1
Enter a number: 153
153 is an Armstrong number
Output 2
Enter a number: 124
124 is not an Armstrong number