diff --git a/Algorithms/Seive-Of-Eratosthenes/Python/sieve_of_eratosthenes.py b/Algorithms/Seive-Of-Eratosthenes/Python/sieve_of_eratosthenes.py new file mode 100644 index 00000000..1216f9b8 --- /dev/null +++ b/Algorithms/Seive-Of-Eratosthenes/Python/sieve_of_eratosthenes.py @@ -0,0 +1,16 @@ +def eratosthenes_sieve(limit): + sieve = [True] * (limit+1) # Initialize the primality list + sieve[0] = sieve[1] = False + result = [] # Result list of prime numbers in given range + for i in range(2, limit+1): + if sieve[i]: + result.append(i) # append primary number to result list + for k in range(2, int(limit/i)+1): # mark folowing non-primary numbers + sieve[i*k] = False + return result # yield the resulting list of primary numbers + +ans=[] +num=101 +ans=eratosthenes_sieve(num) +print("Odd numbers are:",ans) +