python - Program to find the nth prime number - Stack Overflow
stackoverflow.com › questions › 21003381Feb 04, 2017 · Program to find nth Prime Number. def nth_Prime(num): Semi = num*num Res_1 = [True for i in range(Semi+1)] prime = 2 while prime*prime <= Semi: if Res_1[prime] == True: for i in range(prime*prime, Semi+1, prime): Res_1[i] = False prime += 1 Res_2 = [] for i in range(2, Semi+1): if Res_1[i]: Res_2.append(i) return Res_2[num-1] if __name__ == "__main__": num = int(input("Enter nth Number: ")) print(nth_Prime(num))
Generate nth prime number in Python - Code Review Stack Exchange
codereview.stackexchange.com › questions › 158925Generate nth prime number. Given a signature below, write python logic to generate the nth prime number: def nth_prime_number (n): # n = 1 => return 2 # n = 4 => return 7 # n = 10 => return 29. I wrote this code, but couldn't get through: def nth_prime_number (n): if n==1: return 2 count = 1 num = 3 while (count <= n): if is_prime (num): count +=1 if count == n: return num num +=2 #optimization def is_prime (num): factor = 2 while (factor < num): if num%factor == 0: return ...