Answer to Question #236043 in Python for rani

Question #236043

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.




1
Expert's answer
2021-09-11T23:39:34-0400
def Armstrong(A,B):
    for x in range(A, B + 1):
        length = len(str(x))
        count = 0
        t = x
        while t > 0:
            i = t % 10
            count += i ** length
            t //= 10
        if x == count:
            print(x)


print("Sample Input 1")
print(150)
print(200)
print("Sample Output 1")
Armstrong(150,200)
print("\nSample Input 2")
print(1)
print(3)
print("Sample Output 2")
Armstrong(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
New on Blog
APPROVED BY CLIENTS