Python Program to Check Armstrong Number

In this Python program, you’ll learn how to check if the given number is a Armstrong number or not and display it on the console.

How to Check if the Given Number is a Armstrong Number or Not in Python?

A number is said to be an Armstrong number of it is a positive number and if

abc… = an + bn + cn + …

In simple terms, an Armstrong number of 3 digits is the sum of cubes of each digit that is equal to the number itself.

num = 153

sum = 0

temp = num
while temp > 0:
   digit = temp %% 10
   sum += digit ** 3
   temp //= 10

if num == sum:
   print(num,"is an Armstrong number")
else:
   print(num,"is not an Armstrong number")

Output

153 is an Armstrong number