Skip to content

Instantly share code, notes, and snippets.

@mauza
Created January 12, 2015 15:32
Show Gist options
  • Save mauza/2f57f1727a06744f1cb1 to your computer and use it in GitHub Desktop.
Save mauza/2f57f1727a06744f1cb1 to your computer and use it in GitHub Desktop.
Find next prime function
### 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. Actually, just knowing what
# they are would be a plus :)
#
### End Assignment ###
def fnp(n):
# Do your coding here
while True:
isPrime = True
n = n+1
for x in range (2, int(n**0.5)+1):
if n%x == 0:
isPrime=False
break
if isPrime:
return n
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment