Skip to content

Instantly share code, notes, and snippets.

@alothings
Created June 24, 2016 19:29
Show Gist options
  • Save alothings/85002055b221584fac051b97e8824474 to your computer and use it in GitHub Desktop.
Save alothings/85002055b221584fac051b97e8824474 to your computer and use it in GitHub Desktop.
Give an integer n, find the next prime
__author__ = "Alonso Gutierrez"
# Give input integer n, find the next prime
def find_next_prime(n):
isprime = False
n += 1
while (not isprime):
# print n
isprime = True
if n % 2 == 0:
# print 'n is even'
isprime = False
for i in range(3, n/2, 2):
if n % i == 0:
# print 'n in for loop'
isprime = False
n += 1
return n-1
# Test cases
print find_next_prime(6)
print find_next_prime(9)
print find_next_prime(15)
print find_next_prime(788)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment