From 9ee07824cf77176d67b533abef4d05a3f2129f87 Mon Sep 17 00:00:00 2001 From: booboy Date: Fri, 12 Jan 2018 01:40:46 -0600 Subject: [PATCH] added one last change to check to make sure arg n is a positive int --- algorithms/fibonacci/fibonacci_with_lru_cache.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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: