def fibbonacci(n):
if not isinstance(n, int):
raise ValueError('n is int type')
resulet = [0, 1]
if n in resulet:
return resulet[n]
fibbo2 = 0 # n-2的项
fibbo1 = 1 # n-1的项
fibbon = 0 # n
for i in range(2, n + 1):
fibbon = fibbo1 + fibbo2
fibbo2 = fibbo1 # 记录n-2项
fibbo1 = fibbon # 记录n-1项
return fibbon