Created
January 8, 2014 22:05
-
-
Save ericminikel/8325330 to your computer and use it in GitHub Desktop.
Finds the nth prime number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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