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

Share on facebook
Share on twitter
Share on pinterest

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.

 

Subscribe to our Newsletter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Leave a Reply

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