added one last change to check to make sure arg n is a positive int
This commit is contained in:
parent
398c60feb5
commit
9ee07824cf
1 changed files with 8 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue