1num = 1634
2
3# Changed num variable to string,
4# and calculated the length (number of digits)
5order = len(str(num))
6
7# initialize sum
8sum = 0
9
10# find the sum of the cube of each digit
11temp = num
12while temp > 0:
13 digit = temp % 10
14 sum += digit ** order
15 temp //= 10
16
17# display the result
18if num == sum:
19 print(num,"is an Armstrong number")
20else:
21 print(num,"is not an Armstrong number")
22
1# Python program to check if the number is an Armstrong number or not
2
3# take input from the user
4num = int(input("Enter a number: "))
5
6# initialize sum
7sum = 0
8
9# find the sum of the cube of each digit
10temp = num
11while temp > 0:
12 digit = temp % 10
13 sum += digit ** 3
14 temp //= 10
15
16# display the result
17if num == sum:
18 print(num,"is an Armstrong number")
19else:
20 print(num,"is not an Armstrong number")
21
1# Program to check Armstrong numbers in a certain interval
2
3lower = 100
4upper = 2000
5
6for num in range(lower, upper + 1):
7
8 # order of number
9 order = len(str(num))
10
11 # initialize sum
12 sum = 0
13
14 temp = num
15 while temp > 0:
16 digit = temp % 10
17 sum += digit ** order
18 temp //= 10
19
20 if num == sum:
21 print(num)
22