Problem 150927 · easy · Phase 01 Prerequisites & Setup

Narcissistic Numbers

functions · digits · powers

A number is narcissistic (also called an Armstrong number) if it equals the sum of its digits each raised to the power of the number of digits. For example 153 has 3 digits and 1**3 + 5**3 + 3**3 = 1 + 125 + 27 = 153.

Write is_armstrong(n) that returns True if n is narcissistic and False otherwise.

Examples

Input:  n = 153
Output: True

Input:  n = 9474
Output: True

Input:  n = 10
Output: False

Constraints

  • 0 <= n <= 10**12
  • Every single-digit number (including 0) is narcissistic.

Goals

  • Count the digits before processing them
  • Combine digit extraction with exponentiation
Starting Python…