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 f86a6bdCopy full SHA for f86a6bd
maths/is_armstrong_number.py
@@ -0,0 +1,26 @@
1
+def is_armstrong_number(number: int) -> bool:
2
+ """
3
+ Check if a number is an Armstrong number.
4
+ An Armstrong number is a number that is equal to the sum
5
+ of its own digits each raised to the power of the number of digits.
6
+
7
+ >>> is_armstrong_number(153)
8
+ True
9
+ >>> is_armstrong_number(370)
10
11
+ >>> is_armstrong_number(371)
12
13
+ >>> is_armstrong_number(9474)
14
15
+ >>> is_armstrong_number(123)
16
+ False
17
18
+ digits = str(number)
19
+ power = len(digits)
20
+ return number == sum(int(digit) ** power for digit in digits)
21
22
23
+if __name__ == "__main__":
24
+ import doctest
25
26
+ doctest.testmod()
0 commit comments