A Program to Check Armstrong Number

In this example, we are giving a program to check whether an n-digit integer is an Armstrong number or not. An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.


Program to check Armstrong number:

  1. # Check Armstrong number
  2. num = int(input('Enter a number: '))
  3. order = len(str(num))
  4. sum = 0
  5. temp = num
  6. while temp > 0:
  7. digit = temp % 10
  8. sum += digit ** order
  9. temp //= 10
  10. if num == sum:
  11. print(num,"is an Armstrong number")
  12. else :
  13. print(num,"is not an Armstrong number")

Output:

Enter a number: 153
153 is an Armstrong number

Enter a number: 737
737 is not an Armstrong number