python输出斐波那契数列前20项,要求每行输出5列
时间: 2023-11-18 15:04:08 浏览: 155
python 输出斐波那契数列的前20个数 示例
5星 · 资源好评率100%
Sure, here's the code to output the first 20 Fibonacci numbers with 5 numbers per line:
```python
a, b = 0, 1
for i in range(20):
print(b, end=' ')
a, b = b, a + b
if (i+1) % 5 == 0:
print()
```
Output:
```
1 1 2 3 5
8 13 21 34 55
89 144 233 377 610
987 1597 2584 4181 6765
```
阅读全文