Computing the 1000th prime
MRAB
python at mrabarnett.plus.com
Thu Nov 12 14:43:38 EST 2009
Ray Holt wrote:
> 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
>
The indentation starting from the second 'if'.
More information about the Python-list
mailing list