python循环求解斐波那契数列

it2022-05-05  108

List = [1,1] def func(n): for i in range(1,n+1): if i==1 or i == 2: pass else: List.append(List[i-2]+List[i-3]) func(18) print(List)

执行结果:

[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584]

最新回复(0)