Created
January 12, 2015 07:30
-
-
Save makthrow/51f7477b74fa9d1ad1d0 to your computer and use it in GitHub Desktop.
This file contains 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
def find_next_prime(n): | |
# A prime number is a natural number greater than 1 | |
# that has no positive divisors other than 1 and itself. | |
# find the next prime number greater than n by iterating +1 and checking | |
# if the number is prime | |
o = n+1 | |
while check_prime(o) is False: | |
o+=1 | |
print("{} is the next prime after {}".format(o,n)) | |
return o | |
def check_prime(n): | |
i = 2 | |
for i in xrange(i, n): | |
if n % i == 0: | |
#print("{} is not prime".format(n)) | |
return False | |
else: | |
i+= 1 | |
# at this point all numbers up to n have been tested as divisors with no remainder | |
#print("{} is prime".format(n)) | |
return True | |
#check_prime(4) | |
#find_next_prime(3) | |
#for n in xrange(1, 100): | |
#check_prime(n) | |
for n in xrange(1, 100): | |
find_next_prime(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment