Dremendo Tag Line

Input a number and check it is an armstrong number or not using while loop in Python

while Loop - Question 15

In this question, we will see how to input a number and check if it is an armstrong numbers or not in Python programming using while loop. To know more about while loop click on the while loop lesson.

Q15) Write a program in Python to input a number and check if it is an armstrong numbers or not using while loop.

An Armstrong number is a number whose sum of cube of the digits is equal to the original number. Example 153 = 13 + 53 + 33

Program

soc=0
n=int(input('Enter any number '))
on=n    # storing the original number

while n>0:
    d=n%10
    soc=soc+(d*d*d)    # sum of cube of the digits
    n=n//10

if on==soc:
    print('Armstrong Number')
else:
    print('Not Armstrong Number')

Output

Enter any number 153
Armstrong Number
video-poster