Skip to content

Commit a5e562d

Browse files
add input type validation to Fibonacci functions
Refactor Fibonacci function to use a validation helper.
1 parent e2a78d4 commit a5e562d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

maths/fibonacci.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def fib_iterative_yield(n: int) -> Iterator[int]:
5353
...
5454
ValueError: n is negative
5555
"""
56-
if n < 0:
57-
raise ValueError("n is negative")
56+
def fib_iterative(n: int) -> list[int]:
57+
_validate_int_non_negative("n", n)
58+
5859
a, b = 0, 1
5960
yield a
6061
for _ in range(n):

0 commit comments

Comments
 (0)