Answer to Question #248046 in Python for Raju

Question #248046

Armstrong numbers between two intervals


Write a program to print all the Armstrong numbers in the given range A to B(including A and B). An N-digit number is an Armstrong number if the number equals the sum of the Nth power of its digit.


Input

The first line has an integer A.

The second line has an integer B.


Output

Print all Armstrong numbers separated by a space.

If there are no Armstrong numbers in the given range,print -1.


Sample Input 1

1

3

Sample Input 1

1 2 3


Sample Input 2

10

15

Sample Input 2

-1


1
Expert's answer
2021-10-07T10:03:30-0400
a = int(input())
b = int(input())
if a > b:
	a, b = b, a
for i in range(a,b+1):
	s = str(i)
	l = len(s)
	tmp = 0
	for n in s:
		tmp += int(n)**l
	if tmp == i:
		print(i)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS