Python Program to check Armstrong number or not

Hello readers, welcome back, here is another simple python program which checks whether a number is an Armstrong number or not.

Generally, a number is said to be an Armstrong number if the sum of cubes of the digits is equal to its original number.

For Example, 153 is an Armstrong number as its sum of cubes of each digit 13 + 53 + 33 = 153 whereas 456 is not as its sum of cubes of each digit is not 456.

You can watch the video on YouTube here.

Program on Github

Armstrong number – Code Visualization

Task :

Python program to check an integer number is an Armstrong number or not.

Approach :

  1. Read an input number using input() or raw_input().
  2. Check whether the value entered is integer or not.
  3. Check input_num is greater than 0.
  4. Initialise a variable named arm_num to 0.
  5. Find remainder of the input number by using mod (%) operator to get each digit in the number.
  6. Now cube each digit and add it to arm_num.
  7. Floor Divide the number by 10.
  8. Repeat steps 5. 6. 7 until the the input_num is not greater than 0.
  9. If input_num is equal to arm_num, print number is ARMSTRONG.
  10. When input_num is not equals to arm_num, the number is NOT an Armstrong number.

Program on Github

Program :

Output :

Armstrong number - programminginpython.com
Armstrong number – programminginpython.com
Armstrong number - programminginpython.com
Armstrong number – programminginpython.com
Armstrong number - programminginpython.com
Armstrong number – programminginpython.com

Program on Github

Feel free to check some of the other posts here.
Similar Programs :

Leave a Reply