From eaf81ba66eb20699e7fd2d272b90381ef5377a08 Mon Sep 17 00:00:00 2001 From: Archiita Date: Mon, 28 Oct 2019 20:09:52 +0530 Subject: [PATCH] Added Sieve of Erathosthenes in python --- .../Python/sieve_of_eratosthenes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Algorithms/Seive-Of-Eratosthenes/Python/sieve_of_eratosthenes.py 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) +