Python Program to Print all Prime Numbers between an Interval

Created with Sketch.

Python Program to Print all Prime Numbers between an Interval

We have already read the concept of prime numbers in the previous program. Here, we are going to print the prime numbers between given interval.

See this example:

  1. #Take the input from the user: 
  2. lower = int(input(“Enter lower range: “))
  3. upper = int(input(“Enter upper range: “))
  4. for num in range(lower,upper + 1):
  5.    if num > 1:
  6.        for i in range(2,num):
  7.            if (num % i) == 0:
  8.                break
  9.        else:
  10.            print(num)

This example will show the prime numbers between 10 and 50.

Output:

Python Condition And Loops6

 

Leave a Reply

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