Python Function that Check Number is Armstrong

Write a Program to determine if the given number is Armstrong number or not. Print true if number is armstrong, otherwise print false.

Input Format :

Integer N

Output Format :

true or false

Sample Input 1 :

1

Sample Output 1 :

true

Sample Output 2 :

103

Sample Output 2 :

false

Solution :

  1. def check_armstrong(N):
  2. a = 0
  3. k = N
  4. while k > 0:
  5. k = k // 10
  6. a = a + 1
  7. b = 0
  8. k = N
  9. while k > 0:
  10. d = k % 10
  11. k = k // 10
  12. b = b + d**a
  13. if N == b:
  14. return True
  15. else:
  16. return False

  17. N = int(input())
  18. a = check_armstrong(N)
  19. if(a):
  20. print('true')
  21. else:
  22. print('false')
Previous Post Next Post