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``````

TechieClues .
Software Professional, India

IT professional with 15+ years of experience in Microsoft Technologies with a strong base in Microsoft .NET (C#.Net, ASP.Net MVC, ASP.NET WEB API, Webservices,...Read More

https://www.techieclues.com/profile/alagu-mano-sabari-m

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