Skip to content

Commit 647b899

Browse files
committed
Add input validation and docstring to prime check function
1 parent 2f1cb5f commit 647b899

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

maths/prime_check.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88

99
def is_prime(number: int) -> bool:
10+
"""
11+
Check whether a given integer is a prime number.
12+
13+
:param n: integer to check
14+
:return: True if n is prime, False otherwise
15+
:raises ValueError: if n is less than 2
16+
"""
17+
if n < 2:
18+
raise ValueError("n must be an integer greater than or equal to 2")
1019
"""Checks to see if a number is a prime in O(sqrt(n)).
1120
1221
A number is prime if it has exactly two factors: 1 and itself.

0 commit comments

Comments
 (0)