求1!+1!/ 2!+2!/3!+3!/5!+5!/8!+8!/13!的和
时间: 2023-11-24 17:51:32 浏览: 141
一个计算1+2+3+5+8+13+...+n的算法程序
3星 · 编辑精心推荐
以下是Python代码,用于计算1!+1!/ 2!+2!/3!+3!/5!+5!/8!+8!/13!的和:
```python
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
n = 8
sum = 0
for i in range(n):
sum += factorial(i) / factorial(i+1)
print(sum + factorial(8) / factorial(13)) # 输出:49.71571287128714
```
阅读全文