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
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)
pls use a code pasting site, with Python syntax highlighting http://dpaste.com http://pastebin.com http://codepad.org http://dpaste.com/795339/
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/
I dont figure out why you print all of 1000 numbers, the problem only requires the 1000th one
Well, I suggest to make a list of prime numbers, so it is easier for us in pset1b :)
Join our real-time social learning platform and learn together with your friends!