Computing the 1000th prime

Ray Holt mrholtsr at sbcglobal.net
Thu Nov 12 20:11:45 CET 2009


I have an assigment to find the 1000th. prime using python. What's wrong
with the following code:
PrimeCount = 0
PrimeCandidate = 1
while PrimeCount < 2000:
    IsPrime = True
    PrimeCandidate = PrimeCandidate + 2
    for x in range(2, PrimeCandidate):
        if PrimeCandidate % x == 0:
##            print PrimeCandidate, 'equals', x, '*', PrimeCandidate/x
              print PrimeCandidate  
              IsPrime = False
              break
        if IsPrime:
            PrimeCount = PrimeCount + 1
            PrimeCandidate = PrimeCandidate + 2
        print PrimeCandidate
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091112/e76ff289/attachment.html>


More information about the Python-list mailing list