Articles

# Program to print all prime numbers in an interval in python

In this python programming guide, we are going to learn

• program to print all prime numbers in an interval in python

### Python program to print all prime numbers in an interval

The python program to print all prime numbers in an interval is as follows:

``````# Owner : TutorialsInhand Author : Devjeet Roy

lower = int(input("Enter lower range: "))
upper = int(input("Enter upper range: "))

for num in range(lower, upper + 1):
if num > 1:
for i in range(2, (num//2)+1):
if (num % i) == 0:
break
else:
print(num, end=" ")``````

The output of python program to print all prime numbers in a range is as follows:

``````PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter lower range: 10
Enter upper range: 20
11 13 17 19``````

1. We take 2 user input. One for the upper range and one for the lower range. Then within that interval we pull each number and see if it is prime or not.

2. If the number is prime, we print the number else ignore it.

Program to print all prime numbers in a range in python snapshot is given below:

Now using above concept we can write a program to print all prime numbers between 1 to 100 in python or between any range or interval.

Python Numbers Program

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com