In this article, we will write a simple python program which checks whether a number is Armstrong number or Not.
##To find whether number is armstrong or not
## Armstromg number is number where sum of cube of each digit in the number is equal to the number.
sum = 0
while n > 0: ## Loop till n is greater than zero
num = n % 10 ## to find the last digit in the number
sum = sum + (num * num * num) ## find cube of the last digit add it in sum
n = n / 10 ## to find the remaining number except the last number
if __name__ == '__main__':
num = int(raw_input("Enter a number"))
result = armstrong(num)
if result == num:
print "Not armstrong"
Enter a number 153
Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once.