Write a Python Program to Check Armstrong Number

In this tutorial, we will discuss Armstrong numbers and how to check whether a given number is an Armstrong number or not using Python.


Armstrong number is a number that is equal to the sum of the nth power of its digits, where n is the number of digits in the number.

For example, 153 is an Armstrong number because it has three digits and 1^3 + 5^3 + 3^3 = 153.

To check whether a given number is an Armstrong number or not, we need to follow the following steps:

  1. Take the input number from the user.
  2. Find the number of digits in the input number using the len() function.
  3. Initialize a variable sum to 0.
  4. Iterate through each digit of the input number using a loop.
  5. For each digit, raise it to the power of the number of digits and add it to the sum.
  6. Compare the sum with the input number.

If they are equal, then the input number is an Armstrong number; otherwise, it is not.

Now let’s see how to implement this in Python:

# take input from the user
num = int(input("Enter a number: "))

# find the number of digits in the number
num_digits = len(str(num))

# initialize sum to 0
sum = 0

# iterate through each digit of the number
for digit in str(num):
    sum += int(digit) ** num_digits

# check if the sum is equal to the input number
if sum == num:
    print(num, "is an Armstrong number")
else:
    print(num, "is not an Armstrong number")

In this program, we first take the input number from the user and find the number of digits in the number using the len() function.

We then initialize a variable sum to 0 and iterate through each digit of the number using a loop.

For each digit, we raise it to the power of the number of digits and add it to the sum.

Finally, we compare the sum with the input number and print the result.


In conclusion, checking whether a given number is an Armstrong number or not is a simple task that can be easily implemented in Python using the steps mentioned above.