Python Program to Find Armstrong Number between an Interval

Created with Sketch.

Python Program to Find Armstrong Number between an Interval

We have already read the concept of Armstrong numbers in the previous program. Here, we print the Armstrong numbers within a specific given interval.

See this example:

  1. lower = int(input(“Enter lower range: “))
  2. upper = int(input(“Enter upper range: “))
  3. for num in range(lower,upper + 1):
  4.    sum = 0
  5.    temp = num
  6.    while temp > 0:
  7.        digit = temp % 10
  8.        sum += digit ** 3
  9.        temp //= 10
  10.        if num == sum:
  11.             print(num)

This example shows all Armstrong numbers between 100 and 500.

Output:

Python Condition And Loops11

 

Leave a Reply

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