Skip to content

Commit 66e26de

Browse files
authored
Create armstrong_number.py
1 parent c155504 commit 66e26de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

armstrong_number.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Python program to check if the number is an Armstrong number with the index of 3 or not
2+
# for input try numbers 153, 370, 371, 407
3+
4+
# take input from the user
5+
num = int(input("Enter a number: "))
6+
7+
# initialize sum
8+
sum = 0
9+
10+
# find the sum of the cube of each digit
11+
temp = num
12+
while temp > 0:
13+
digit = temp % 10
14+
sum += digit ** 3
15+
temp //= 10
16+
17+
# display the result
18+
if num == sum:
19+
print(num, "is an Armstrong number.")
20+
else:
21+
print(num, "is not an Armstrong number.")
22+
23+
24+
25+
# Originally contribution by denz647

0 commit comments

Comments
 (0)