1) x isn't used the code, it should be for the next step in the writing, I suppose.
2) Unused isprime variable, it should be. (only set)
3) We have to go to y include, so to y+1 (exclude)
4) The code fail for y<2, I suppose you know that, not a serious issue
5) three spaces for indentation is not common, I use tab, (or 2 or 4 spaces).
Here is a code that do the job, with minimal changes, hope it will be helpful.
Then some more modifications, light...
BR
F
from math import sqrt
def PrimeGenerator(y):
primes = [2]
for item in range(3,y+1,2):
isprime = True
a = sqrt(item) + 1
for divisor in primes:
if divisor >= a:
break
if item % divisor ==0:
isprime = False
break
if isprime:
primes.append(item)
return primes
for y in range(100):
print(y, PrimeGenerator(y))
# A variation, without the use of sqrt
def primes(n):
if n<2:
return []
prime=[2]
for i in range(3, n+1, 2):
for p in prime:
if p*p>i: # then i is a prime number
prime.append(i)
break
if i%p==0: # then i is a composed number
break
return prime
for n in range(100):
print(n, primes(n))
if n>1: assert primes(n) == PrimeGenerator(n) , ("test fail for", n)