用py编写程序,计算S=1+1/3-1/5+1/7-1/9+...的结果
时间: 2023-10-06 12:06:38 浏览: 196
PyPI 官网下载 | aridity-21-py2.py3-none-any.whl
def sum(n):
r = 0
while n >= 1:
if n % 2 == 0:
r -= 1 / (n * (n + 1))
else:
r += 1 / (n * (n + 1))
n -= 1
return r
result = sum(50)
阅读全文