python - Generating a list of prime numbers. - beginner -
i starting out, , i've written following code , have been trying debug few hours. not getting basic here. want code give me list of prime numbers length specified in call parameter. started out list of first four, things going , make coding easier. basic algorithm want use add 2 last member of list, check whether last number in list prime determining whether other members of list divide it, starting first member. i'd stop checking @ point when value of divisor exceeds square root of candidate prime, haven't figured out how attempt that.
i getting error in line 5, can't understand, i'm sure there other problems code well.
def prime_list(length): l = [2, 3, 5, 7] j = 9 while length > len(l): prime = true = 0 divisor in l: while divisor in range (0, len(l) - 2) , prime == true: if j % divisor == 0: prime = false if prime == false: j = j + 2 else: l = l.append(j) return l
.append()
modifies list in place returns none
. don't assign none
returns l
.
Comments
Post a Comment