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 = 200
For example, if we take number 153, the sum of the cube of digits 1, 5, 3 is
n_1 = int(input())
n_2 = int(input())
res = []
for i in range(n_1,n_2 + 1):
i_str = str(i)
tmp = 0
for d in i_str:
tmp += int(d)**len(i_str)
if tmp == i:
res.append(i)
print(*res)
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment