Check Armstrong Number

Check whether a given integer is an Armstrong (narcissistic) number.

BeginnerTopic: Conditional Programs
Back

Python Check Armstrong Number Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# Program to check Armstrong number (order 3)

num = int(input("Enter an integer: "))

digits = str(num)
power = len(digits)

total = 0
for d in digits:
    total += int(d) ** power

if total == num:
    print(num, "is an Armstrong number")
else:
    print(num, "is not an Armstrong number")
Output
Enter an integer: 153
153 is an Armstrong number

Understanding Check Armstrong Number

An Armstrong number is equal to the sum of its digits each raised to the power of the number of digits.

We convert the number to a string to iterate over digits, then compare the sum with the original number.

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.

Table of Contents