added one last change to check to make sure arg n is a positive int

This commit is contained in:
booboy 2018-01-12 01:40:46 -06:00
parent 398c60feb5
commit 9ee07824cf

View file

@ -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: