Hey Everyone,<br>I'm currently trying to work through MIT's opencourseware and am using python. The second assignment they offer is to determine the 1000th prime number. Below is the code I am using:<br><br>#Assignment 1a<br>
#Determine the 1000th prime number<br>candidate=3<br>#Already know that 2 is prime<br>primeCount=1<br>while (primeCount<=1000):<br>        for i in range (2,candidate):<br>                if ((candidate%i)==0):<br>                        print(candidate, " is not a prime")<br>
                else:<br>                        print(candidate, " is a prime!")<br>                        primeCount+=1<br>        candidate+=2<br><br><br><br><br>Now I'm not looking for a solution, but I'm hoping that someone can at least tell me where the error in my logic is.<br>
The outer loop keeps count and will keep iterating until the 1000th prime number has been found.<br>The inner loop just attempts to divide the candidate number by each possible factor until it's reached, and then increases the candidate number value by two since even numbers above 2 aren't prime.<br>
The if statement inside the inner loop simply checks if there is a remainder when attempting to divide the candidate by the possible factor. If there isn't, its a factor and we can print "not a prime". If there is always a remainder, nothing is a factor and so the candidate is a prime.<br>
<br>I figured it seemed simple enough, but I keep getting a massive output and almost nothing listed is a correct prime number.<br><br>Please be gentle, its my first post and I haven't programmed in ages :)<br>-Matty<br>