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
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.
divisor=top_num while divisor!=0 if num%divisor==0: cont+=1 divisor-=1 if cont==2 print num
you can divide the number succesively, if you cont is equal 2, this mean that is prime otherwise no. excuse dont speak english
everyone ..please use dpaste.com or ideone.com it make reading the code a hell lot easy..
Join our real-time social learning platform and learn together with your friends!