Skip to content

Commit 1de9ed7

Browse files
committed
Added a program to check whether a number is disarium or not
1 parent c79034c commit 1de9ed7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def is_disarium(num):
2+
"""
3+
Check if a number is a Disarium number.
4+
A Disarium number is a number in which the sum of its digits
5+
powered with their respective positions is equal to the number itself.
6+
7+
Example:
8+
135 -> 1¹ + 3² + 5³ = 135 ✅
9+
"""
10+
digits = str(num)
11+
total = 0
12+
position = 1
13+
14+
for i in digits:
15+
total += int(i) ** position
16+
position += 1
17+
18+
if total == num:
19+
return True
20+
else:
21+
return False
22+
23+
24+
if __name__ == "__main__":
25+
test_numbers = [89, 135, 175, 518, 9, 10]
26+
for n in test_numbers:
27+
print(f"{n}{'Disarium' if is_disarium(n) else 'Not Disarium'}")

0 commit comments

Comments
 (0)