第六题

戏唱故梦2025-05-22

代码

y = 0
n = 1
while True:
    term = 1 / (2 * n - 1)
    if y + term >= 3:
        break
    y += term
    n += 1
print(f"y的最大值: {y}")
print(f"对应的n值: {n-1}")

结果

y的最大值: 2.994437501289942
对应的n值: 56
ON THIS PAGE