Check if a number (as a string) is a narcissistic/Armstrong number.
(number: str)
| 1 | def is_armstrong_number(number: str) -> bool: |
| 2 | """Check if a number (as a string) is a narcissistic/Armstrong number.""" |
| 3 | # Logic: Get the exponent (number of digits) |
| 4 | exponent = len(number) |
| 5 | |
| 6 | # Logic: Sum each digit raised to the power in a single line |
| 7 | # This uses a generator, which is memory efficient. |
| 8 | total = sum(int(digit) ** exponent for digit in number) |
| 9 | |
| 10 | # Return the boolean result instead of printing |
| 11 | return total == int(number) |
| 12 | |
| 13 | # --- Main execution --- |
| 14 | user_input = input("Enter the number: ") |