diff --git a/algorithms/fibonacci/fibonacci_with_lru_cache.py b/algorithms/fibonacci/fibonacci_with_lru_cache.py index ff2b331..f32d6a8 100755 --- a/algorithms/fibonacci/fibonacci_with_lru_cache.py +++ b/algorithms/fibonacci/fibonacci_with_lru_cache.py @@ -1,8 +1,16 @@ #!/usr/bin/env python3 from functools import lru_cache + @lru_cache(maxsize = 1000) def fibonacci(n): + # check input type. must be positive integer. + if type(n) != int: + raise TypeError("n must be a positive int") + if n < 1: + raise ValueError("n must be a positive int") + + # compute the nth term if n == 1: return 1 elif n == 2: