Hey guys, in this blog we will see a Python Program to Find Armstrong Number in an Interval.
# Program to check Armstrong numbers in a certain interval lower = 100 upper = 5000 for num in range(lower, upper + 1): # order of number order = len(str(num)) # initialize sum sum = 0 temp = num while temp > 0: digit = temp % 10 sum += digit ** order temp //= 10 if num == sum: print(num)
153 370 371 407 1634
Here we have simply defined a lower and upper bound of the range in which we need to find the Armstrong numbers. Check out this blog to understand Armstrong numbers: Python Program to Check Armstrong Number
Check out our other python programming examples…