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.
A=int(input())
B=int(input())
for i in range(A, B+1):
x = len(str(i))
sum1 = 0
temp = i
while temp > 0:
digit = temp % 10
sum1 += digit ** x
temp //= 10
if i == sum1:
print(i)
Comments
Leave a comment