A = int(input())
B = int(input())
for num in range(A, B + 1):
# order of number
order = len(str(num))
# initialize sum
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
In this python program it has two test cases, in this two test cases one test case was getting expected output and second test case are not getting expected output. Please give me expexted output for two test cases. Thank you !
Hints:
Sample Input 1
150
200
Sample Output 1
153
Sample Input 2
1
3
Sample Output 2
1 2 3
import math
a = int(input())
b = int(input())
for i in range(a, b+1):
ln = len(str(i))
s = 0
for j in str(i):
s += pow(int(j), ln)
if s == i:
print(i, end=" ")
print()
Sample Input 1
150
200
Sample Output 1
153
Sample Input 2
1
3
Sample Output 2
1 2 3
Comments
Leave a comment