[Tutor] Prime numbers
rabidpoobear at gmail.com
Sun Mar 28 10:46:44 CEST 2010
On Sat, Mar 27, 2010 at 5:08 PM, yd <ydmt923 at gmail.com> wrote:
> Having a problem finding the first 1000 prime numbers, here is my code:-
> n =3
> counter =1
> while counter <=1000:
> for x in range(3,int((n**0.5)),2):
> if n%x != 0:
> The problem is, it prints 2 and then does nothing, yet if i try and close,
> it says program is still running do you want to kill it, is there a way to
> do this with lists, i know python has a prime function but i am not going to
> use it because i want to solve this problem without 'cheating'.Thanks.
> What 'problem' are you trying to solve?
In general, anytime you can use a premade solution, you are at an advantage,
That's one of the marks of a truly good programmer - being able to reuse as
much code as possible.
Unless it's a homework problem and he said "don't use the prime function"
because in this case, your goal is to learn how to write a prime function,
not to calculate primes.
I.E. it's the doing, not the task. And if that's the case, please let us
know that it's homework. We will still help you, we just follow certain
when providing homework assistance so as not to "give it away" and still
allow you to reason / come up with the solution on your own, as your teacher
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor