Question #257735

write a program to find armstrong numbers in the given range A to B (including A and B). an N -digit number is armstrong number if the number is equal to the sum of the Nth power of its digits.


Expert's answer

a = int(input("A = "))
b = int(input("B = "))
nums = []
for n in range(a, b+1):
    if n == sum([int(i)**len(str(n)) for i in str(n)]):
        nums.append(n)
print(f"Armstrong numbers in the range {a} to {b}:")
print(*nums, sep=',')




LATEST TUTORIALS
APPROVED BY CLIENTS