Problem 103279 · medium · Phase 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 153 has 3 digits and 1**3 + 5**3 + 3**3 = 1 + 125 + 27 = 153. 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 = 153
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…