Skip to content

Commit b085575

Browse files
Create armstrong.py
1 parent dc0a515 commit b085575

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

armstrong.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def power(x, y):
2+
3+
if y == 0:
4+
return 1
5+
if y % 2 == 0:
6+
return power(x, y // 2) * power(x, y // 2)
7+
8+
return x * power(x, y // 2) * power(x, y // 2)
9+
10+
def order(x):
11+
12+
n = 0
13+
while (x != 0):
14+
n = n + 1
15+
x = x // 10
16+
17+
return n
18+
19+
def isArmstrong(x):
20+
21+
n = order(x)
22+
temp = x
23+
sum1 = 0
24+
25+
while (temp != 0):
26+
r = temp % 10
27+
sum1 = sum1 + power(r, n)
28+
temp = temp // 10
29+
30+
return (sum1 == x)
31+
32+
x = 153
33+
print(isArmstrong(x))
34+
35+
x = 1253
36+
print(isArmstrong(x))

0 commit comments

Comments
 (0)