-
Notifications
You must be signed in to change notification settings - Fork 0
/
NextPrime.py.py
47 lines (40 loc) · 940 Bytes
/
NextPrime.py.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
### 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 ###
# Do your coding here
n = raw_input("What is your number? ")
n = int(n)
def is_prime(n):
if n <= 1:
return False
for i in range(2, n):
if (n % i) == 0:
return False
return True
def print_next_prime(n):
number = n
while True:
number += 1
if n <= 1:
print(2)
break
elif is_prime(number):
print(number)
break
print_next_prime(n)