Skip to content

Instantly share code, notes, and snippets.

@rockydcoder
Created May 28, 2015 19: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 rockydcoder/cda26048bf89d65f6f10 to your computer and use it in GitHub Desktop.
Save rockydcoder/cda26048bf89d65f6f10 to your computer and use it in GitHub Desktop.
### Assignment ###
#
# Your assignment is to implement the
# following function: `find_next_prime`.
# As the name states, given the number `n` the
# function should return the next closest prime.
#
# Examples:
# * `find_next_prime(6)` should return 7.
# * `find_next_prime(10)` should return 11.
# * `find_next_prime(11)` should return 13.
#
# You can use whatever you want (data structures,
# language features, etc).
#
# Unit tests would be a plus.
#
### End Assignment ###
def find_next_prime(n):
# Do your coding here
while(True):
n += 1
if is_prime(n):
return n
def is_prime(n):
no_of_factors = 0
for i in range(1, n + 1):
if n % i == 0:
no_of_factors += 1
if no_of_factors > 2:
return False
else:
return True
print find_next_prime(6)
print find_next_prime(10)
print find_next_prime(11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment