Python Program to Read Prime Numbers in a Range using Sieve of Eratosthenes














































Python Program to Read Prime Numbers in a Range using Sieve of Eratosthenes



def prime_eratosthenes(n):  #define a function 
    prime_list = []                   # create a empty list
    for i in range(2, n+1):          # create a irritation of range to start 2 to n+1 
        if i not in prime_list:          #check i value in prime list or not
            print (i)                  #print the prime number
            for j in range(i*i, n+1, i):    # j value start i**2 and increase as step count increase like (4,8,2) ->>> 4,6
               prime_list.append(j)           # add j value in prime_list 


n=input("Provide this n value: ") # user input
prime_eratosthenes(n)                                               #fun calling.


More Articles of Ravi Shanker Singh:

Name Views Likes
Python Program to Read Prime Numbers in a Range using Sieve of Eratosthenes 230 0

Comments