用python语言解决列表问题

计算裴波那契数列的前n项值 ,然后保存到列表中并输出

f=[]
f.append(1)
f.append(1)
n=int(input())
for i in range(2,n):
    f.append(f[i-1]+f[i-2])
print(f)
def fib(n):
    res = [1,1]
    if n==1:return [1]
    if n==2:return res
    while n>2:
        res.append(res[-1]+res[-2])
        n -= 1
    return res

for i in range(1,16):
    print(fib(i))

输出结果:
[1]
[1, 1]
[1, 1, 2]
[1, 1, 2, 3]
[1, 1, 2, 3, 5]
[1, 1, 2, 3, 5, 8]
[1, 1, 2, 3, 5, 8, 13]
[1, 1, 2, 3, 5, 8, 13, 21]
[1, 1, 2, 3, 5, 8, 13, 21, 34]
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]