Finding the nth number of primes
- by Braxton Smith
I can not figure out why this won't work. Please help me
from math import sqrt
pN = 0
numPrimes = 0
num = 1
def checkPrime(x):
'''Check\'s whether a number is a prime or not'''
prime = True
if(x==2):
prime = True
elif(x%2==0):
prime=False
else:
root=int(sqrt(x))
for i in range(3,root,2):
if(x%i==0):
prime=False
break
return prime
n = int(input("Find n number of primes. N being:"))
while( numPrimes != n ):
if( checkPrime( num ) == True ):
numPrimes += 1
pN = num
print("{0}: {1}".format(numPrimes,pN))
num += 1
print("Prime {0} is: {1}".format(n,pN))