We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2a78d4 commit b83a2c7Copy full SHA for b83a2c7
maths/armstrong_number.py
@@ -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