Python 代码计算多项分式的和 (保留两位小数)
n = int(input('请输入项数 n: '))
result = 0
for i in range(1, n+1):
term = 1 / (i * (i + 1))
result += term
print('{:.2f}'.format(result))
运行上述代码,输入项数 n,程序会计算多项分式的和,并保留两位小数输出结果。
原文地址: https://www.cveoy.top/t/topic/WOs 著作权归作者所有。请勿转载和采集!