Chris Angelico rosuav at
Sun Aug 14 14:47:44 CEST 2011

On Sun, Aug 14, 2011 at 1:36 PM, Abhishek Jain
<abhishekjain.cooldude.93 at> wrote:
> ## this is to find the 1000th prime number
> number = 3
> while number < 10000:
>     ###initialize stuff
>     counter = 1

I think your main problem here, and you have several, is with this
variable 'counter'. Have a really good think about what the counter is
supposed to do, and ensure that it's really doing it. If, as I
suspect, it's meant to be counting prime numbers such that you print
the thousandth, then you want to set it once, outside the loop, and
increment it only when you find a prime number. (Point to note: The
first prime number is 2, not 3.)

You asked for code. This looks like a homework assignment, so I won't
actually do your work for you, for that would defeat the purpose. But
think about every variable you use, what it ought to be doing, and
what it's actually doing. Step through the program in your own head,
and be sure you fully understand what it's doing.

Chris Angelico

More information about the Python-list mailing list