Q:

write python program to check whether 3 digit number is armstrong or not

0

write python program to check whether 3 digit number is armstrong or not

Armstrong number:

A number is called Armstrong number if it is equal to the sum of the cubes of its own digits.

For example: 153 is an Armstrong number since 153 = 1*1*1 + 5*5*5 + 3*3*3.

The Armstrong number is also known as narcissistic number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

num = int(input("Enter a number: "))
if num>999:
   print('number should be include 3 digits maximum')
else:
 sum = 0  
 temp = num  
  
 while temp > 0:  
   digit = temp % 10  
   sum += digit ** 3  
   temp //= 10  
  
 if num == sum:  
    print(num,"is an Armstrong number")  
 else:  
    print(num,"is not an Armstrong number")  

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now