斐波那契数列python,输出前20项
时间: 2023-12-21 22:06:55 浏览: 152
fibo.rar_55_fibo_python用递归写斐波那契数列fibo
5星 · 资源好评率100%
以下是Python输出斐波那契数列前20项的代码:
```python
fib = [0, 1]
for i in range(2, 20):
fib.append(fib[i-1] + fib[i-2])
print(fib)
```
输出结果为:[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]
阅读全文