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

hi, i am having trouble with problem 2 of ps1. I keep either getting wrong numbers or nothing. Can someone please help me. Thanks This is what I have so far. import math answer=math.log(2) primecount=0 candidate=1 while primecount<999: candidate=candidate+2 divisor=3 not_prime = False while (divisor

OpenStudy (anonymous):

sorry it didn't post the bottom but it ends with primecount= primecount 1 print answer

OpenStudy (anonymous):

Were you able to do Problem 1? You only need to make some very minor changes to the solution for problem 1 to get it to solve problem 2. I'd reccomend starting with problem 1 and modifying it to solve problem 2. If you want some tips, copy and paste your problem 1 solution and I or somebody else here may be able to advise you.

OpenStudy (anonymous):

this is my solution to problem 1, I would appreciate any help with problem 2. primecount=0 candidate=1 while primecount<999: candidate=candidate+2 divisor=3 not_prime = False while (divisor<candidate/2) and (not_prime == False): if candidate%divisor == 0: not_prime = True divisor = divisor+2 if not_prime == False: primecount= primecount+1 print candidate

OpenStudy (anonymous):

Okay, I see what you've changed between the two. Get rid of the "while primecount<998 and not_prime == False:" at the end. Move "answer= answer + math.log(candidate)" into the last if statement. It should work then.

OpenStudy (anonymous):

thanks, got it working

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!