Having a try at computing the sieve of Eratosthenes <p>I'm an absolute novice to python but I am trying to compute something that should act like the sieve of Eratosthenes.</p> <p>I'm going to start easy and just create a set with all integers from 2 up to 100. Let's call that set S.</p> <p>I then want to create a set of all integers n such that 2n is contained in that set, let's call it P1. In other words, a set of the integers 2, 4, 6, 8 etc.</p> <p>I want to then do the same thing but with P2 = 3n and then P3 = 5n.</p> <p>In the end I want to return all integers of my set S but disregard the integers in P1, P2 and P3.</p> <p>How would I go on about doing this?</p> <p>My try:</p> <pre><code> numbers=set(range(2,100)) </code></pre> <p>but I'm stuck on creating the other sets and disregarding them!</p> <p>Thanks.</p> <p>My idea so far:</p> <pre><code>def sieve(n): S = set(range(2, 100)) P1 = set(range(0, 100, 2)) P2 = set(range(0, 100, 3)) P3 = set(range(0, 100, 5)) P5 = set(range(0, 100, 7)) return S-P1-P2-P3-P5 print (sieve(100)) </code></pre>