Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 13 Online
OpenStudy (anonymous):

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

OpenStudy (espex):

It appears you are kicking it out of the while if it is even.

OpenStudy (espex):

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.

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

eSpex, chribonn: Thank you so much for your help! Best regards, Yahmelord

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!