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

so i have issues with the first problem set and the problem number 1: generating prime numbers i've written a while loop, that works on teh variable count which should stay under 1000. bit i cant't find the right candidates or the right divisors, and my code is probably wrong too. anyone see my mistake? count = 1 candidate = 3 divisor = candidate - 1 if not candidate % 2 == 0: while count < 1000: if candidate % divisor == 0: count += 1. else: candidate +=1. divisor +=1 print count print candidate

OpenStudy (anonymous):

First of all, you should base your code on the natural definition of a prime number: "An integer that cannot be divided by any other integers other than 1 and itself". That should help you start. Try listing the steps that you would take to determine a prime number, on paper.

OpenStudy (jhonny111s):

divisor=top_num while divisor!=0 if num%divisor==0: cont+=1 divisor-=1 if cont==2 print num

OpenStudy (jhonny111s):

you can divide the number succesively, if you cont is equal 2, this mean that is prime otherwise no. excuse dont speak english

OpenStudy (anonymous):

everyone ..please use dpaste.com or ideone.com it make reading the code a hell lot easy..

OpenStudy (anonymous):

http://dpaste.com/hold/573107/

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!