Skip to content

Commit 86b7a61

Browse files
authored
Create armstrongno.py
Check Armstrong number (for 3 digits)
1 parent 99cf7d7 commit 86b7a61

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

armstrongno.py

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

0 commit comments

Comments
 (0)