forked from subhalaha131/python-questions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong.py
More file actions
33 lines (27 loc) · 831 Bytes
/
armstrong.py
File metadata and controls
33 lines (27 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'''
Armstrong number in python
A 3 digit armstrong number is a number that is equal to the sum of cubes of its digits and a 4 digit armstrong number is a number that consists of four such digits whose fourth powers when added together give the number itself
'''
num = int(input("Enter a number: "))
sum = 0
temp = num
if ( num <= 999):
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
elif ( (num > 999) and (num < 10000)):
while temp > 0:
digit = temp % 10
sum += digit ** 4
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
else:
print(num,"is not an Armstrong number")