Skip to content

Fix: Multiple errors in fibonacci search. #2659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 8, 2020
10 changes: 10 additions & 0 deletions searches/fibonacci_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ def fibonacci(k: int) -> int:
5
>>> print(fibonacci(15))
610
>>> print(fibonacci('a'))
Traceback (most recent call last):
ValueError: k must be an integer.
>>> print(fibonacci(-5))
Traceback (most recent call last):
ValueError: k integer must be greater or equal to zero.
"""
if not isinstance(k, int):
raise ValueError("k must be an integer.")
if k < 0:
raise ValueError("k integer must be greater or equal to zero.")
if k == 0:
return 0
elif k == 1:
Expand Down