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

i am on lecture4 and atempting the first assignment. Im stuck on the first problem on how to write a program that prints out the first 1000th prime numbers. i'm guessing you have to use a for loop, but I'm just not sure how to actually go about writing the code for it.

OpenStudy (anonymous):

The tutorial in the Python documentation gives examples of flow control tools http://docs.python.org/tutorial/controlflow.html#more-control-flow-tools try writing down in words what you need to do then see if you can translate that into code like: i need to test a bunch of numbers till i find 1000 primes to test a number i need to see if it is evenly divisible by any number between 2 and n-1

OpenStudy (anonymous):

Like what bwCA said, just try to visualize what exact you want to do. You may even want to consider trying to find the first few prime numbers (besides 2 considering it said to skip it in the instructions because the test should be only concerned with odd numbers to make things easier for you) by hand. A hint though: it says use the remainders as a test (a%b). If something divides evenly into something other than 1 and itself, then it's not prime. I hope that helps, goodluck.

OpenStudy (anonymous):

thank you, i figured it out.

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!