python求求fibonacci数列四十个数
时间: 2023-10-17 15:10:26 浏览: 127
python使用函数求fibonacci数
以下是求解 Fibonacci 数列前 40 个数的 Python 代码:
```python
fibonacci = [0, 1]
for i in range(2, 40):
fibonacci.append(fibonacci[i-1] + fibonacci[i-2])
print(fibonacci)
```
输出结果为:
```
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141]
```
阅读全文