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 NOutput Format :
true or falseSample Input 1 :
1Sample Output 1 :
trueSample Output 2 :
103Sample Output 2 :
false
Input Format :
Integer NOutput Format :
true or falseSample Input 1 :
1Sample Output 1 :
trueSample Output 2 :
103Sample Output 2 :
falseSolution :
- def check_armstrong(N):
- a = 0
- k = N
- while k > 0:
- k = k // 10
- a = a + 1
- b = 0
- k = N
- while k > 0:
- d = k % 10
- k = k // 10
- b = b + d**a
- if N == b:
- return True
- else:
- return False
- N = int(input())
- a = check_armstrong(N)
- if(a):
- print('true')
- else:
- print('false')
Tags:
Solutions