Python Program to Print Prime Numbers in a Given Interval

This Python program explains how you can print prime numbers in a given interval in python using loops.

A number is a prime number if the following conditions are satisfied

  • It is a Positive Number
  • It is Greater than 1.
  • Has no other factors except 1 and the number itself.

Some of the examples of a prime number are 2,3 etc.

How to Print Prime Numbers in a given interval in Python?

# Author : Abandantcode.com
# Python program to display prime numbers within a given interval

minRange = 1
maxRange = 10

print("Prime numbers")

for num in range(minRange, maxRange + 1):
   if num > 1:
       for i in range(2, num):
           if (num % i) == 0:
               break
       else:
           print(num)

Output

Prime numbers
2
3
5
7

In the above python program, we store the intervals in the minRange and maxRange variables and find the prime numbers between this range using the for loop and the modulus operatos in python.