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.
Inputs:
10
15
Output:
-1
lwr = int(input('Enter lower bound here:'))
uppr = int(input('Enter upper bound here:'))
for numb in range(lwr, uppr + 1):
# order of number
odr = len(str(numb))
# initialize sum
sum = 0 tem = numb while tem > 0:
digit = tem % 10
sum += digit ** odr
tem //= 10
if numb == sum:
print("The Armstrong numbers are: ",numb)
Comments
Leave a comment