Skip to content

Commit b83a2c7

Browse files
committed
Added armstrong_number.py program for hactoberfest
1 parent e2a78d4 commit b83a2c7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

maths/armstrong_number.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def is_armstrong(num: int) -> bool:
2+
"""
3+
Check if a number is an Armstrong number.
4+
5+
Args:
6+
num (int): Number to check
7+
8+
Returns:
9+
bool: True if Armstrong, False otherwise
10+
"""
11+
digits = str(num)
12+
power = len(digits)
13+
total = sum(int(digit) ** power for digit in digits)
14+
return total == num
15+
16+
17+
if __name__ == "__main__": # <-- corrected here
18+
# Example usage
19+
number = 153
20+
if is_armstrong(number):
21+
print(f"{number} is an Armstrong number.")
22+
else:
23+
print(f"{number} is not an Armstrong number.")

0 commit comments

Comments
 (0)