TechieClues TechieClues
Updated date Mar 22, 2021
In this code snippet, we will show you how to check if the number is an Armstrong Number or not in python.

Armstrong number is a number that is equal to the sum of cubes of its digits.

Example:

370 = 3*3*3 + 7*7*7 + 0*0*0 =>    370 is an Armstrong number.

Python program to check if the number is an Armstrong Number or not. If you don't have knowledge of the below topics, please go through the topics before continue to this,

# To check if a number is Armstrong Number or not

number = int(input("Enter a number to check : "))
i = 0
temp = number
while temp > 0:
    digit = temp % 10
    i += digit ** 3
    temp //= 10

# Print result
if number == i:
    print(number, "is an Armstrong number")
else:
    print(number, "is not an Armstrong number")

Output:

Enter a number to check : 370
370 is an Armstrong number
Enter a number to check : 125
125 is not an Armstrong number
Enter a number to check : 153
153 is an Armstrong number

ABOUT THE AUTHOR

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

There are no comments. Be the first to comment!!!