Armstrong numbers between two intervals
Write a program to print all the Armstrong numbers in the given range
The first line has an integer
Print all Armstrong numbers separated by a space.
If there are no Armstrong numbers in the given range, print
For
A = 150 and B = 200For example, if we take number 153, the sum of the cube of digits
1, 5, 3 is 13 + 53 + 33 = 153.
So, the output should be
153.
Sample Input 1
150
200
Sample Output 1
153
Sample Input 2
1
3
Sample Output 2
1 2 3
6 / 8 Test Cases Passed
*When you submit the code, we will run it against a set of exhaustive test cases.
Input
1
2
10
15
Your Output
Expected
-1
Source code
A=int(input())
B=int(input())
for i in range(A, B+1):
n = len(str(i))
n_sum = 0
temp = i
while temp > 0:
d = temp % 10
n_sum += d ** n
temp //= 10
if i == n_sum:
print(i)
Sample Output1
Sample Output2
Comments
Leave a comment