From a5e562df5e7d7bf501dd38d285ac4f930c70dc11 Mon Sep 17 00:00:00 2001 From: Abhiranjan Kumar <2400030581@kluniversity.in> Date: Mon, 3 Nov 2025 13:29:14 +0530 Subject: [PATCH] add input type validation to Fibonacci functions Refactor Fibonacci function to use a validation helper. --- maths/fibonacci.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/maths/fibonacci.py b/maths/fibonacci.py index 71ff479f9cc2..e4873d8488b2 100644 --- a/maths/fibonacci.py +++ b/maths/fibonacci.py @@ -53,8 +53,9 @@ def fib_iterative_yield(n: int) -> Iterator[int]: ... ValueError: n is negative """ - if n < 0: - raise ValueError("n is negative") +def fib_iterative(n: int) -> list[int]: + _validate_int_non_negative("n", n) + a, b = 0, 1 yield a for _ in range(n):