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

I'm having problems on PS1. I have written several iterations of this and sometimes it prints, sometimes it doesn't.

OpenStudy (anonymous):

findprime = int(raw_input ('For which prime are you looking?')) if findprime == 1: #block deals with 1, 2, and 3, which have different properties than remaining primes print (2) elif findprime == 2: print (3) else: count = int(3) num_candidate = int(5) #testing starts at 5 while count <= findprime: for devisor in range (3, int(num_candidate ** 0.5), 2): if num_candidate%devisor == 0: num_candidate += 2 #if evenly divisible, move onto next odd candidate print (num_candidate) else: count += 1 num_candidate += 2 print (num_candidate) break if count == findprime: print (num_candidate)

OpenStudy (rsmith6559):

You're printing num_candidate from 3 different places. It will help you if you add some text to the print statements so that you know which one is printing: print( "from else num_candidate ==", num_candidate ) Logically, I would expect a break statement when "num_candidate%devisor == 0" to reset the for loop.

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!