Created
May 28, 2015 19:05
-
-
Save rockydcoder/cda26048bf89d65f6f10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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. | |
# | |
### 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