Skip to content

Commit f24ceb0

Browse files
committed
Function now raises an error when given invalid input
1 parent 2e88127 commit f24ceb0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

maths/combinations.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ def combinations(n: int, k: int) -> int:
2626
1
2727
2828
>>> combinations(-4, -5)
29-
Invalid value for n and/or k given.
30-
-1
29+
Traceback (most recent call last):
30+
ValueError: Please enter positive integers for n and k where n >= k
3131
"""
3232

3333
# If either of the conditions are true, the function is being asked
3434
# to calculate a factorial of a negative number, which is not possible
3535
if n < k or k < 0:
36-
print("Invalid value for n and/or k given.")
37-
return -1
36+
raise ValueError("Please enter positive integers for n and k where n >= k")
3837
return int(factorial(n) / ((factorial(k)) * (factorial(n - k))))
3938

4039

0 commit comments

Comments
 (0)