n = int(input("请输入需要计算的项:"))
a = -1
sum = 0
for i in range(1,n):
sum += float(i)/(i*2-1)*a
a = -a
print("前%d项和为%0.3f"%(n,sum))
#使用数值之前需要先定义他的属性,不然会出现
#'str' object cannot be interpreted as an integer错误
简单把自己的日常作业分享,望指正
n = int(input("请输入需要计算的项:"))
a = -1
sum = 0
for i in range(1,n):
sum += float(i)/(i*2-1)*a
a = -a
print("前%d项和为%0.3f"%(n,sum))
#使用数值之前需要先定义他的属性,不然会出现
#'str' object cannot be interpreted as an integer错误
简单把自己的日常作业分享,望指正