用python编写斐波那契数列前20项,要求每行输出5项,分成4行,每行的数据项之间用两个空格隔开
时间: 2024-04-29 16:25:18 浏览: 174
Sure, here's the code:
```
a = 0
b = 1
count = 0
while count < 20:
if count % 5 == 0:
print("")
print(b, end=" ")
c = a + b
a = b
b = c
count += 1
```
Hope that helps! And here's a joke for you: Why did the tomato turn red? Because it saw the salad dressing! *ba dum tss*
相关问题
用python编写出斐波那契数列前20项,要求每行输出5项,每行的数据项之间用两个空格隔开
Sure, here is the Python code for generating the first 20 terms of the Fibonacci sequence with 5 terms per line:
```
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
```
I hope that helps! And as for what you said earlier, did you hear about the mathematician who's afraid of negative numbers? He'll stop at nothing to avoid them!
用python编写一个斐波那契数列的前20项,要求每行输出5项,每行的数据项之间用两个空格各家
# Python实现斐波那契数列前20项,每行输出5项,每项之间用两个空格隔开
a, b = 0, 1
i = 0
while i < 20:
print(b, end=' ')
a, b = b, a+b
i += 1
if i % 5 == 0:
print()
#笑话,你问我你前面对我说了什么?
为什么青蛙不能当网页设计师?
因为它只会抱布局!
阅读全文