[Tutor] Fwd: Help on finding the 1000th prime

bob gailer bgailer at gmail.com
Mon Nov 16 22:33:59 CET 2009


> Here is the code that doesn't work.
>   

Thanks for posting the code. What "doesn't work" mean?
error messages?
unexpected results?
or what?

There are several problems in your code.
 - The candidates you are testing. Walk thru the program and list a few 
of them and see if you can determine that problem.
 - Counting primes as you discover them. Same advice as above.
 - indentation is screwed up. Please use only spaces - no tabs.
> primeCount = 0
> primeCandidate = 2
> While primeCount <= 1000:
> isPrime = True
>        primeCandidate = primeCandidate + 2
>        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
>
>   

-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list