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.
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)
Comments
Leave a comment