Advertisement
ALENTL

amstrong1.py

Sep 13th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. '''Write a program to input a number and check it is an amstrong number or not'''
  2. '''Amstrong number means sum of the cubes of its digit must be same as the original number'''
  3. '''Eg: 143 = 3^3 + 4^3 + 1^3 != 143'''
  4. '''Eg: 153 = 3^3 + 5^3 + 1^3'''
  5.  
  6. num = int(input('The number is: ',))
  7. sum = 0
  8.  
  9. a = num
  10. while a > 0:
  11. digit = a%10
  12. sum = sum + digit**3
  13. a = a//10
  14.  
  15. if num == sum:
  16. print('The number', sum, 'is an Amstrong number')
  17. else:
  18. print('The number', sum, 'is not an Amstrong number')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement