MCPcopy Create free account
hub / github.com/geekcomputers/Python / is_armstrong_number

Function is_armstrong_number

Armstrong_number.py:1–11  ·  view source on GitHub ↗

Check if a number (as a string) is a narcissistic/Armstrong number.

(number: str)

Source from the content-addressed store, hash-verified

1def 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 ---
14user_input = input("Enter the number: ")

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected