Read & Print Prime Numbers In A Range Using Sieve Of Eratosthenes In Python

In this Basic Python Program, we will have a look at how to “print prime numbers in a range” with the help of Python Programming Language.

Python Program To Print Prime Numbers In a Range

n=int(input("Enter upper limit of range: "))

sieve=set(range(2,n+1))

while sieve:

    prime=min(sieve)

    print(prime,end="\t")

    sieve-=set(range(prime,n+1,prime))

 print()

In the above Python Program, we printed prime numbers in a range using Sieve of Eratosthenes.

 

Leave a Reply

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

Shopping cart