[Tutor] Making a Primary Number List generator

Daniel Magruder dsm3 at att.net
Sat May 11 22:44:05 CEST 2013


Dear Tutor at Python.org,
I am new to the python language and have been teaching myself through various online resources. I found an exercise where I am to create a program that prints a list of the first 1000 prime numbers. After many attempts and looking at other answers for other ways around the problem (which I did not understand), I am seeking your guidance.
Here is what I have so far. While I understand there are many ways to do this, I would like advice on how to finish this program based on the initial path I started out on.

def counting_primes():
	primelist = [] # I want a list of 1000 primes
	prime = f(0) # so that when I divid I get a true non int answer
	x = 1 # to test and make sure no other number goes into prime besides prime and one
	while len(primelist)<1000: # start a loop for as long as my list is not 1000 items in length
 		if prime % x == num and x < prime:
			x = x + 1  # keep the dividing loop going until  x and prime are equal
			if prime % x == 0: and prime != x: # if prime is not yet a prime number i.e. 8 and x is a number like 4, this prevents false positives
				x= x+1
				if prime = x:
					primelist = primelist + x # add x to my list of primes
					prime = prime + 1 # check to see if next number is prime

	return primelist

Please walk me through any logical errors, I really want to understand this.
Sincerely,
Dan


More information about the Tutor mailing list