Skip to content

Instantly share code, notes, and snippets.

@ericminikel
Created January 8, 2014 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericminikel/8325330 to your computer and use it in GitHub Desktop.
Save ericminikel/8325330 to your computer and use it in GitHub Desktop.
Finds the nth prime number.
primes = []
x = 2
nthprime = 1000 # set to 1000 to get the 1000th prime number
while len(primes) < nthprime:
isPrime = True
for item in primes:
if item > x**.5:
break
if x % item == 0:
isPrime = False
break
if(isPrime):
primes.append(x)
x += 1
print primes[nthprime-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment