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

Stuck on Problem Set 1A. I keep getting a "RESTART" message in the Python Shell when I run this. Am I close to figuring this out? primecount=0 intcount=3 while primecount < 1000: if intcount%2 != 0: #limits to odd numbers for x in xrange(2,intcount): #range of divisors from 2 to integer itself if intcount%x==0: #see if division by divisor has no remainder and therefore is not prime intcount+=1 break elif intcount==x: #if the loop runs its course and divisor equal

OpenStudy (anonymous):

intcount+=1 primecount+=1 print primecount break else: #add one to divisor to keep checking for prime continue else: #if even, go to next integer intcount+=1 print "The 1000th prime number is %s." %(primecount)

OpenStudy (anonymous):

pls use a code pasting site, with Python syntax highlighting http://dpaste.com http://pastebin.com http://codepad.org http://dpaste.com/795339/

OpenStudy (anonymous):

I realized I was misunderstanding what a "for" loop does -- I thought I could use the for loop sequence number as a variable. So I created a divisor variable to cover that. Code is here, and it works! Thanks bwCA http://dpaste.com/795350/

OpenStudy (anonymous):

I dont figure out why you print all of 1000 numbers, the problem only requires the 1000th one

OpenStudy (anonymous):

you can use the for loop sequence number http://dpaste.com/795407/

OpenStudy (anonymous):

Well, I suggest to make a list of prime numbers, so it is easier for us in pset1b :)

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!