def prime_gen(n):
    primes = [2]
nextPrime = 3
while nextPrime < n:
    isPrime = True
i = 0
squareRoot = int(nextPrime ** 0.5)
while primes[i] <= squareRoot:
    if nextPrime % primes[i] == 0:
        isPrime = False
i += 1
if isPrime:
    primes.append(nextPrime)
nextPrime += 2
print(primes)
Базовый генератор простых чисел в Python