Created
January 12, 2015 15:32
-
-
Save mauza/2f57f1727a06744f1cb1 to your computer and use it in GitHub Desktop.
Find next prime function
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
### 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