方法一

def fbnc(n):
    if not isinstance(n,int):
        raise ValueError('n must be int')
    if n == 1:
        return [1]
    elif n == 2:
        return [1,1]
    elif n > 2:
        l = [1,1]
        for i in range(n-2):
            l.append(l[-1] + l[-2])
        return l

方法二

def fbnc2(n):
    a,b = 1,1
    for i in range(n-2):
        a,b = b,a+b
    return b