Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11386 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2011-08-14 13:47 +0100 |
| Last post | 2011-08-14 13:47 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: question Chris Angelico <rosuav@gmail.com> - 2011-08-14 13:47 +0100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-08-14 13:47 +0100 |
| Subject | Re: question |
| Message-ID | <mailman.2269.1313326067.1164.python-list@python.org> |
On Sun, Aug 14, 2011 at 1:36 PM, Abhishek Jain <abhishekjain.cooldude.93@gmail.com> 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
Back to top | Article view | comp.lang.python
csiph-web