Skip to content

Commit 6604830

Browse files
authored
Create P81_armstrong number.py
1 parent db193cd commit 6604830

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Programs/P81_armstrong number.py

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

0 commit comments

Comments
 (0)