Python Program to Check Armstrong Number
In This tutorial, you will learn how to write a Python program to check armstrong number or not.
What is armstrong number: An Armstrong number is a number such that the sum ! of its digits raised to the third power is equal to the number ! itself. For example, 371 is an Armstrong number, since ! Readmore
num = 371 # Changed num variable to string, # and calculated the length (number of digits) order = len(str(num)) # initialize sum sum = 0 # find the sum of the cube of each digit temp = num while temp > 0: digit = temp % 10 sum += digit ** order temp //= 10 # display the result if num == sum: print(num," Number is an Armstrong number") else: print(num," Number is not an Armstrong number")
371 Number is an Armstrong number