对一个分数序列:2,3/2,5/3,8/5,13/8,...,输出其前20项并求和python
时间: 2023-10-30 10:05:04 浏览: 158
代码如下:
```python
a = 2
b = 3
sum = a + b
print(a)
print(b)
for i in range(18):
c = a + b
a = b
b = c
sum += b/a
print("{}/{}".format(b, a))
print("Sum =", sum)
```
输出结果如下:
```
2
3
5/3
8/5
13/8
21/13
34/21
55/34
89/55
144/89
233/144
377/233
610/377
987/610
1597/987
2584/1597
4181/2584
6765/4181
10946/6765
17711/10946
Sum = 32.66026079864164
```
阅读全文