Finding Nth Prime In Python
I wrote the following segment of code in Python to find the nth number. I don't understand why it doesn't work. Can you please only give me a hint or point out exactly which bit is
Solution 1:
Your dont print
anything. Your function works.
term = int(input("What prime do you want to find? "))
prime_list=[2]
defprime_search(term):
x=3whilelen(prime_list) <= term:
ifall(x % y != 0for y inrange(2,x)):
prime_list.append(x)
x += 1return prime_list[term-1]
print(prime_search(term))
Output:
What prime do you want to find? 511
However i advise you to look up prime sieve if you really want to use this.
Post a Comment for "Finding Nth Prime In Python"