# How to Print all Prime Numbers in an Interval using Python?

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Prime number is defined as a number not divisible by any other number except 1 and itself. Hence to ascertain that a number is prime, it should be checked for divisibility by all numbers between 1 and itself excluding both.

Following program lists all prime numbers between 1 to 100. Outer loop generates numbers in this range. Inner loop goes from 2 to each number in outer loop and successively checks divisibility by % operator. If it is not divisible by all numbers in inner range, it prints out that number

for i in range(101):
for j in range(2,i-1):
if i%j==0: break
else:
print (i)
Updated on 21-Feb-2020 12:55:50