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

Hey I'm working on PS1 and I was just wondering what I did wrong http://dpaste.com/568800/ when i run it the output is 2003.. which is not the 1000th prime.

OpenStudy (anonymous):

Actually, it's because you simply prints the 1000th odd number after 3. x = 2n + 1, with n starting from 1 to 9999, would yield odds, and exempt even numbers. And therefore, if x % 2 != 0 is pretty much useless. All of your numbers were odds already, so of course they can't be divided by 2.

OpenStudy (anonymous):

http://dpaste.com/568815/ I was able to define prime and print the info. now can someone help me how to make it stop at the 1000th.

OpenStudy (anonymous):

Oh and when comment out the "##print n, 'equals', x, '*', n/x ##print if any" it will only show prime number between 1-9999.

OpenStudy (anonymous):

Wait, what about your earlier tuple method?

OpenStudy (anonymous):

I couldnt set a solid definition of 'prime' so i decided to go with another method.

OpenStudy (anonymous):

Here's a hint: There whould be two loops in there. One for the prime candidates, and the other for the divisors.

OpenStudy (anonymous):

Who would you set the loop for the divisors? for the prime candidates i got x = 3 y = 2 while x > y: if x % y == 0: x = x + 2 y = 2 else: ... ## loop for divisors go here i guess

OpenStudy (anonymous):

I wouldn't divide it with 2. It'll always be false, since your candidates are all odd numbers.

OpenStudy (anonymous):

In theory this should work but I think im sending it into an infinite loop... http://dpaste.com/568850/

OpenStudy (anonymous):

in line 2 your limit is 9999 so it is not infinite.

OpenStudy (anonymous):

http://dpaste.com/hold/568878/ Like I said, doing it without tuples/lists is a royal pain in the rearside....

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!