So I am trying to find 6th prime number, and the while loop in getPrime is not working properly. It is supposed to end when count is bigger than num, but it doesn't. It'd be great if you could help me find out why.
import math
def isPrime(num):
if num == 1:
return False
if num % 2 == 0 and num > 2:
return False
for i in range(3, int(math.sqrt(num))+1, 2):
if num % i == 0:
return False
return True
def getPrime(num):
count = 1
while count < num:
for i in range(1, 20):
#print "check"
if isPrime(i):
print "prime", i
count += 1
print "count", count
else:
continue
print i
return i
getPrime(6)
imay not have been defined/initialized at all when you get to the end of the function.getPrime(6)?? want first 6 prime numbers or prime numbers from the first 6 numbers??