Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### 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 of Assignment
- import math
- def isPrime(num):
- if num == 0 or num ==1:
- return False
- elif num == 2 or num ==3:
- return True
- for i in range(2, int(math.sqrt(num)+1),1):
- if num % i ==0:
- return False
- return True
- def find_next_prime(n):
- i = n
- found = False
- while not found:
- i+=1
- if isPrime(i):
- found = True
- return i
- print find_next_prime(6)
- print find_next_prime(10)
- print find_next_prime(11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement