0

Hi, we started doing programing at uni and i got interested so am learning some python at home. just started on generators and thought i'd write a function to generate prime numbers, as you do:

```
def primes(p=2):
while True:
for n in range(2,p):
if p % n == 0:
p += 1
primes(p)
z = p
p += 1
yield z
```

it does sort out the primes but it also lets a few non-primes through. An example output is:

2 3 5 7 11 13 17 19 23 **27** 29 31 **35** 37 41 43 47 53 59 61 67 71 73 79 83 **87** 89 **95** 97

as you can see 27, 35, 87 and 95 shouldn't be there.

what i don't get is why it lets these numbers through, i.e. 35, but filters out 15! grrr...

thanks

*Edited 6 Years Ago by iloveannaw*: n/a