Answer to Question #235070 in Python for kaavya

Question #235070

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 digits.

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.

Explanation

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




1
Expert's answer
2021-09-10T01:47:34-0400
def Amstrong(number1,number2):
    for n in range(number1, number2+1):
        l = len(str(n))
        count = 0
        t = n
        while t > 0:
            d = t % 10
            count += d ** l
            t //= 10
        if n == count:
            print(n)
print("Sample Input 1")
print(150)
print(200)
print("Sample Output 1")
Amstrong(150,200)


print("\n\nSample Input 2")
print(1)
print(3)
print("Sample Output 2")
Amstrong(1,3)

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
APPROVED BY CLIENTS