Return True if n is a narcissistic number or False if it is not. >>> all(narcissistic_number(n) for n in PASSING) True >>> any(narcissistic_number(n) for n in FAILING) False
(n: int)
| 68 | |
| 69 | |
| 70 | def narcissistic_number(n: int) -> bool: |
| 71 | """Return True if n is a narcissistic number or False if it is not. |
| 72 | |
| 73 | >>> all(narcissistic_number(n) for n in PASSING) |
| 74 | True |
| 75 | >>> any(narcissistic_number(n) for n in FAILING) |
| 76 | False |
| 77 | """ |
| 78 | if not isinstance(n, int) or n < 1: |
| 79 | return False |
| 80 | expo = len(str(n)) # the power that all digits will be raised to |
| 81 | # check if sum of each digit multiplied expo times is equal to number |
| 82 | return n == sum(int(i) ** expo for i in str(n)) |
| 83 | |
| 84 | |
| 85 | def main(): |