Could someone please take a look at my answer for assignment #1? I've spent days on this and I couldn't figure out what's wrong with my code... Thank you so much in advance. Link: http://codepad.org/wmOUKOnt
It appears you are kicking it out of the while if it is even.
Try just incrementing your counter to 1000 and print the result when finished. By setting it up like this: number = 3 counter = 1 while counter <= 1000: for divisor in range(2,number): if number%divisor==0: print 'number is equal to: ', number counter+=1 number+=2 print 'The 1000th prime number is:', number This will allow you to see it increment.
What is wrong is that you are incrementing counter each time a number being testing does not give a remainder of zero. You need to increment counter after having tested ALL possible values (divisors) that may be divisible by number. I had posted my solution. If you get stuck message me and I'll post it. Hope this helps
yahmelord: One area of improvement to your solution would be to factor in that no number can be divisible by more than half its value. For example the largest number 11 can be divisible by would be (11 / 2 + 1). This should improve the efficiency of your solution.
eSpex, chribonn: Thank you so much for your help! Best regards, Yahmelord
Join our real-time social learning platform and learn together with your friends!