Python Program to Find Armstrong Number in an Interval – 2023

Hey guys, in this blog we will see a Python Program to Find Armstrong Number in an Interval.

Code

# 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)

Output

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

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 521

Leave a Reply

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