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

I am working on problem set 1 and have hit a bit of a wall. Can somebody help?

OpenStudy (anonymous):

What have you tried so far?

OpenStudy (anonymous):

primeCounter = 1 numbertoTest = 3 while primeCounter < 1000: for divisor in range (2, numbertoTest): if numbertoTest % divisor == 0: numbertoTest = numbertoTest + 2 else: divisor = divisor + 1 if numbertoTest != 0: primeCounter = primeCounter + 1 numbertoTest = numbertoTest + 2 print numbertoTest

OpenStudy (anonymous):

I think you should experiment a bit with how for loops work, the else: divisor = divisor + 1 section doesn't do anything. Also, why are you checking to see if numbertoTest doesn't equal zero? Where and why would your code set it to zero? Both those are tangential to the problem your having though. What's the algorithm you're using? Describe it in as much detail as possible.

OpenStudy (anonymous):

Looking at your first if/else loop. If the number is 9. Range will be 2,9. So...9/2 has a remainder. Div + 1. 9/3 = no remainder. so, add 2 to numerator. 11/3 = no remainder. Add 1 to divisor. 11/4 - no rem. 11/5 no remainder, etc, up to 11/10, then no remainder, so go to next IF statement where the counter is increased. Your algorithm is incorrect. You need a command to break the cycle, before you do all the calculations for the entire range of "divisor in range(2,numbertoTest).

OpenStudy (anonymous):

I made some typos...please forgive me - so text should be: Looking at your first if/else loop. If the number is 9. Range will be 2,9. So...9/2 has a remainder. Div + 1. 9/3 = no remainder. so, add 2 to numerator. 11/3 = remainder. Add 1 to divisor. 11/4 - rem. 11/5 remainder, etc, up to 11/10, then remainder, so go to next IF statement where the counter is increased. Your algorithm is incorrect. You need a command to break the cycle, before you do all the calculations for the entire range of "divisor in range(2,numbertoTest).

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!
Latest Questions
ARTSMART: Art!
51 minutes ago 4 Replies 3 Medals
Jasonisyours: What were the key causes of the French Revolution in 1789?
1 hour ago 2 Replies 4 Medals
PureSoulless: Why is the word "Pedophile" always censored in yt vids?
23 hours ago 3 Replies 0 Medals
Jalli: What's 58x3634u00b07
19 hours ago 6 Replies 3 Medals
arriya: who wanna play roblox
1 day ago 5 Replies 1 Medal
brianagatica14: Any artist on here?
3 days ago 7 Replies 2 Medals
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!