Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions maths/armstrong_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def is_armstrong(num: int) -> bool:
"""
Check if a number is an Armstrong number.

Args:
num (int): Number to check

Returns:
bool: True if Armstrong, False otherwise
"""
digits = str(num)
power = len(digits)
total = sum(int(digit) ** power for digit in digits)
return total == num


if __name__ == "__main__": # <-- corrected here
# Example usage
number = 153
if is_armstrong(number):
print(f"{number} is an Armstrong number.")
else:
print(f"{number} is not an Armstrong number.")