I seem to have got myself into a endless loop on the finding the 100th prime number project and cant see what is causing it any help anyone could give me would be appreciated. Here is my code. primeCount = 2 primeCheck = 3.0; divisor = 2; result = 0; while primeCount <= 1000: while divisor < primeCheck/2: result = primeCheck % divisor; if result == 0: primeCount = primeCount + 1; primeCheck = primeCheck + 2; else: divisor = divisor + 1; print "The 1000th prime number is ", primeCheck, ".";
I might be reading this wrong, but you never increment divisor in the second while loop. So once you get primeCheck up to 5 it can't escape that loop. The rest seems ok.
The logic here is missing something. Try steping through the code one line at a time with a paper/pencil, and at each line write the current values for primeCount, divisor, primeCheck, and result. Also you can try adding print statements to see where your code is getting stuck.
Join our real-time social learning platform and learn together with your friends!