Kent Johnson <[email protected]> wrote on 11/16/2009 04:00:02 PM:
> ---------- Forwarded message ----------
> From: Ray Holt <[email protected]>
> Date: Mon, Nov 16, 2009 at 1:55 PM
> Subject: RE: [Tutor] Help on finding the 1000th prime
> To: Kent Johnson <[email protected]>
>
>
> I hit the send button before I was ready. Here is the code that doesn't
> work.
Not to nit pick, but try and copy the code exactly as you have it.
The code below has capitalization where it doesn't belong and indenting
is not consistent, so there should be plenty of syntax errors if you tried
to run it. This makes it hard to figure out where your particular problem
is. Not sure if its a syntax problem or a algorithm problem. Indentation
is key in Python so without showing exactly what you have loops and
branching is hard or impossible to follow. This is also why it is good to
include exactly what error you are experiencing.
> primeCount = 0
> primeCandidate = 2
You might find it easier to start with a different primeCandidate
and handle 2 as a special case.
> While primeCount <= 1000:
> isPrime = True
> primeCandidate = primeCandidate + 2
primeCandidate is going to be 4,6,8,10,12,14,16,18,...
which won't yield many primes. see comment above
> for x in range(2, primeCandidate):
> if primeCandidate % x == 0:
> print primeCandidate, "equals", x, "*", primeCandidate/x
> isPrime = False
> Print primeCandidate
> break
> If isPrime:
> primeCount = primeCount + 2
> Print primeCandidate
>
It is hard to follow what is in which loop with the rest of the
code, so I can't say much more on where you are having problems. It looks
like you have the parts there just a question of what goes where.
Chris
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor