Python Program to check Armstrong number or not
Hello readers, welcome back, here is an 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 where as 456 is not as its sum of cubes of each digit is not 456.
Python program to check an integer number is an Armstrong number or not.
- Read an input number using
- Check whether the value entered is integer or not.
- Check input_num is greater than 0.
- Initialise a variable named
remainderof the input number by using mod (%) operator to get each digit in the number.
- Now cube each digit and add it to
- Floor Divide the number by 10.
- Repeat steps 5. 6. 7 until the the input_num is not greater than 0.
input_numis equal to
arm_num, print number is ARMSTRONG.
input_numis not equals to
arm_num, the number is NOT an Armstrong number.
input_num = (input("Enter any number: "))
arm_num = 0
val = int(input_num)
while val > 0:
reminder = val % 10
arm_num += reminder ** 3
val //= 10
if int(input_num) == arm_num:
print(input_num, 'is an ARMSTRONG number')
print(input_num, 'is NOT an armstrong number')
print("That's not a valid number, Try Again !")
Hello readers, welcome back, here is an another simple python program which checks whether a number is an Armstrong…programminginpython.com