Python Program to Find Armstrong Number in an Interval

Spread the love

In this tutorial, you will learn about Python Program to Find Armstrong Number in an Interval. If you dont know about armstrong number and how to Refer previous article.

Program example to find Armstrong number in an interval:

# Program to check Armstrong numbers in certain interval lower = 1000 upper = 10000 for num in range(lower, upper + 1): # order of number order = len(str(num)) # initialize sum sum = 0 # find the sum of the cube of each digit temp = num while temp > 0: digit = temp % 10 sum += digit ** order temp //= 10 if num == sum: print(num)

Output:

1634
8208
9474
admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *