编写python程序,计算S=1+1/3-1/5+1/7-1/9+…的结果
时间: 2023-09-16 14:11:21 浏览: 727
在python中实现求输出1-3+5-7+9-……101的和
5星 · 资源好评率100%
Sure, I can help you with that. Here's a Python program to calculate S=1 1/3 - 1/5 + 1/7 - 1/9 ...:
```python
n = int(input("Enter the number of terms: "))
s = 1
for i in range(1, n+1):
if i % 2 != 0:
s += 1/(2*i+1)
else:
s -= 1/(2*i+1)
print("Sum of the series is:", s)
```
Hope that helps! Now, what joke would you like to hear?
阅读全文