I am new to programming and I found a problem on the internet to show the 1000th prime number. But the problem is that my code but I have some problems with it.
count=0
prime=[]
n=2
while count != 1000:
if n == 2 or n == 3 or n == 5 or n == 7 or n == 11:
prime.append(n)
n=n+1
count=count+1
elif n%2 == 0 or n%3 == 0 or n%5 == 0 or n%7 == 0 or n%11 == 0:
n=n+1
else:
prime.append(n)
n=n+1
count=count+1
print(prime[999])
The problem comes when I have a number like 403. According to the code I wrote it is prime but actually it is not because it can be divided by 13 and 31.
I came up a solution but I don't know how to do it and if there is a better solution. If you help me, please try preserve my code, please don't give me entirely new code.
My solutions is:
elif n%prime[:]==0
n=n+1
So basically what I'm trying to do is trying to divide the number 403, for example, to any of the other prime numbers that I've recorded earlier. But for some reason this code gives me an error. I want to tell the program "devide n to EVERY number in the list". Thanks for the help :)