I have managed to solve the 7th Project Euler problem, however I think it can be improved by a lot, I am by no means a professional programmer or even consider myself really good at it. Any improvements / suggestions would be really helpful.
Problem statement:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
This is my solution.
counter = 2
n = 10001
for i in range(3, 1000000, 2):
k = 1
while k < i:
k += 2
if i % k == 0:
break
if k + 2 == i:
counter += 1
if counter == n:
print(i)
raise ZeroDivisionError
The program does skip 2 and 3, in an attempt of mine to make it faster. At the end I raise an error in order to stop the program from looping.