I wrote this a few years ago. This one actually works.
#! /usr/local/bin/python
import math
def sieve(limit):
param = int(math.ceil(math.sqrt(limit)))
primes = []
for i in range(2,param):
state = True
for j in range(2,i):
if i==j:
continue
elif i%j==0:
state = False
break
if state:
primes.append(i)
end = len(primes) - 1
go = primes[end] + 1
for i in range(go,limit):
state = True
for key, prime in enumerate(primes):
if i == prime:
continue
elif i % prime == 0:
state = False
break
if state:
primes.append(i)
print primes
sieve(100000)
Replace "100000" with whatever limit you want to cap it at.
Name:
Anonymous2013-11-06 1:25
>le pedophile forced indentation
Name:
Anonymous2013-11-06 2:04
A boy died in 1932 by a homicidal murderer. He buried him in the ground when he was still alive. The murdered chanted, "Toma sota balcu" as he buried him. Now that you have read the chant, you will meet this little boy. In the middle of the night he will be on your ceiling. He will suffocate you like he was suffocated. If you post this, he will not bother you. Your kindness will be rewarded.
Name:
Anonymous2013-11-06 16:03
>>2
It doesn't print the first four primes twice nerd.