Problem 103279 · medium · Level 01 Prerequisites & Setup

Armstrong Number Check

loops · digits · powers · accumulation

A number with k digits is an Armstrong number if the sum of each digit raised to the power k equals the number itself. For instance 407 has 3 digits and 4**3 + 0**3 + 7**3 = 64 + 0 + 343 = 407. Write is_armstrong(n) that returns True when n is an Armstrong number and False otherwise. Single-digit numbers (including 0) are all Armstrong numbers.

Examples

Input:  n = 407
Output: True

Input:  n = 10
Output: False
Explanation: 1**2 + 0**2 = 1, which is not 10.

Constraints

  • 0 <= n <= 10**9

Goals

  • Use one loop to count digits and another to process them
  • Compare an accumulated value with the original number
Starting Python…