Assignment 1 1000th prime code. I think i have some sort of semantic error going on,and i am completely stuck on this. http://codepad.org/bczvKExW
The only time "isprime" is true is on the first prime number. That "for" part will keep looping because it will never become "true" again. I think that it might work if you put the statement "isprime = true" in the beginning of the "for" condition, that way, it won't be an infinite loop. I'm just a noob at programming though, so this might not work, lol.
Here are the values of your variables at the start: counter = 0, isprime = True, testnumber = 1 Since counter < 1000, the interpreter goes in the while loop. You say x in range(2, testnumber) which evaluates to range(2,1), which is an empty list. So it never enters the for loop and counter is never incremented. Hence the infinite loop.
Such a simple mistake,and i thank you greatly maitre_kaio,so here is my updated version,its a basic generator of primes without input.Advice would be a pleasure. http://codepad.org/SQEvhoCw
I thinks it's simple (which is good), my only comment: for readability you should indent your comments on the same level as your code.
Thanks! I was trying to go for simple,ill be sure yo indent as well next time.
If you want to know more about readability for python, these are some guidelines: http://www.python.org/dev/peps/pep-0008/
Now look at your results. Are all these results really primes ?
Join our real-time social learning platform and learn together with your friends!