jeudi 30 septembre 2021

Making a list of the first n prime numbers in Python

I'm currently new to programming, and I am currently struggling to make a list of the first n prime numbers using if/else/while or recursion.

This is the current messy code I have. It currently runs an infinite amount of times:

def prime_list(n):
    num = 1
    div = 1
    brac = []
    if len(brac) <= n:
        if num >= div:
            if num % div != 0:
                append.count(num)
            if num % div == 0:
                div += 1
        else:
            num += 1
    return brac

I know my code definitely isn't close to what I desire to want, but can you lead me into the right direction on how to fix it? Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire