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

For Problem Set 1, question 1. I think I know what I need to do, but I don't know how to do it. Any suggestions? Is there a better way to post the code in these forums? bignum = 1000 count = 2 for i in range(bignum): count = count + 1 prime = 3 primetest = prime + 2 if primetest % ((primetest - 2) > 0: count + 1 ...from here on I'm kind of lost. I know I need to count up to 1,000, and then I spit out the number. I'm not sure how to figure out how to loop with the divisors either. My thought was to test by subtracting 2 each time.

OpenStudy (anonymous):

1.You should use a while loop to know when you reach the 1000th prime number. 2. Before the while loop you can use the statement prime=3 like you have, but inside the while loop you should change prime to prime + 2 so it will check each odd number. 3. You then need a for loop to check if its a prime number. You can subtract by 2 as you were thinking in your for loop.

OpenStudy (anonymous):

Thank you....I've been trying to figure this out for a while. I don't want to look at others examples. This will help move me in the right direction.

OpenStudy (anonymous):

okay, here is my next try...does anyone have a suggestion? I hope I am getting closer. prime = 3 count = 2 while count < 1001: prime = prime + 2 divide = prime * 0.5 for prime in range(3,prime,2): if prime % divide > 0: divide = divide - 2 else: count +=1 prime +=1 print prime Thanks for any help you can give me.

OpenStudy (anonymous):

First issue I see is that you use prime to increment your for loop and as the variable. So every time you enter the for loop prime is being set to 3. Hope that helps getting you started again.

OpenStudy (anonymous):

I feel like this could be baby steps for a while. Here is where I'm at now. I created a new variable within the loop that uses "prime" within it. I'm hoping this will help increment it. It doesn't work yet, but maybe it is closer to working. prime = 3 count = 2 while count < 1001: test = prime + 2 divide = test * 0.5 for test in range(3,prime,2): if test % divide > 0: divide = divide - 2 else: count +=1 prime +=1 print prime I accidentally closed the question, and I have no idea how to re-open it.

OpenStudy (anonymous):

So now your for loop starts at 3 and ends at 3 with steps of 2 (for the first loop at least)

OpenStudy (anonymous):

nfarve, when you're done with me, you're going to have a huge SmartScore. Thanks for your help.

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
luvnickk: If yalll fw the weeknd your a 10 !!
18 seconds ago 13 Replies 2 Medals
Ash2746: Anyone know anything interesting about the Cold War?
15 minutes ago 11 Replies 2 Medals
Austinsbabygirl4life: Texas schools look funn
41 minutes ago 6 Replies 2 Medals
chuu: Is it (Hunt 30-31) or (Hunt 30-1) in MLA?
2 hours ago 1 Reply 0 Medals
luvnickk: what typa music yall listen to ?
1 hour ago 28 Replies 3 Medals
GothgirlLillian: Is music considered art?
1 hour ago 8 Replies 0 Medals
luvnickk: am newwww
14 hours ago 0 Replies 0 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!