Return True if n is an Armstrong number or False if it is not. >>> all(armstrong_number(n) for n in PASSING) True >>> any(armstrong_number(n) for n in FAILING) False
(n: int)
| 14 | |
| 15 | |
| 16 | def armstrong_number(n: int) -> bool: |
| 17 | """ |
| 18 | Return True if n is an Armstrong number or False if it is not. |
| 19 | |
| 20 | >>> all(armstrong_number(n) for n in PASSING) |
| 21 | True |
| 22 | >>> any(armstrong_number(n) for n in FAILING) |
| 23 | False |
| 24 | """ |
| 25 | if not isinstance(n, int) or n < 1: |
| 26 | return False |
| 27 | |
| 28 | # Initialization of sum and number of digits. |
| 29 | total = 0 |
| 30 | number_of_digits = 0 |
| 31 | temp = n |
| 32 | # Calculation of digits of the number |
| 33 | number_of_digits = len(str(n)) |
| 34 | # Dividing number into separate digits and find Armstrong number |
| 35 | temp = n |
| 36 | while temp > 0: |
| 37 | rem = temp % 10 |
| 38 | total += rem**number_of_digits |
| 39 | temp //= 10 |
| 40 | return n == total |
| 41 | |
| 42 | |
| 43 | def pluperfect_number(n: int) -> bool: |