[Python] Basic prime number generator in Python

Discussão em 'Python' iniciado por Stack, Novembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    Just wanted some feedback on my prime number generator. e.g. is it ok, does it use to much resources etc. It uses no libraries, it's fairly simple, and it is a reflection of my current state of programming skills, so don't hold back as I want to learn.

    def prime_gen(n):

    primes = [2]
    a = 2

    while a < n:

    counter = 0

    for i in primes:
    if a % i == 0:
    counter += 1

    if counter == 0:
    primes.append(a)
    else:
    counter = 0

    a = a + 1

    print primes

    Continue reading...

Compartilhe esta Página