Find the 10,001st prime number.
I am trying to do Project Euler problems without using copying and pasting code I don't understand. I wrote code that finds whether a number is prime or not and am trying to modify it to run through the first 10,001 primes. I thought that this would run through numbers until my break, but it's not working as intended. Bear in mind I have tried a few other ways to code this and this was the one I thought could work. I am guessing that I somewhat made a mess of what I had before.
import math
import itertools
counter = 0
counters = 0
for i in itertools.count():
for n in range (2, math.ceil(i/2)+1):
if i%n == 0:
counter+=1
if counter == 0 or i == 2:
counters+=1
if counters == 10001:
break
else:
pass
print(i)
See Question&Answers more detail:os