1num = 370
2# Changed num variable to string,
3# and calculated the length (number of digits)
4order = len(str(num))
5# initialize sum
6sum = 0
7# find the sum of the cube of each digit
8temp = num
9while temp > 0:
10 digit = temp % 10
11 sum += digit ** order
12 temp //= 10
13# display the result
14if num == sum:
15 print(num,"is an Armstrong number")
16else:
17 print(num,"is not an Armstrong number")
18#Output-- 370 is an Armstrong number
1a = 1634
2aa = str(a)
3lenn = len(aa)
4count = 0
5for i in range(lenn):
6 count += int(aa[i]) ** 4
7if count == a :
8 print("Yes")
9else:
10 print('No')
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