逃兵
发表于 2021-1-30 17:25:48
n = int(input('请输入数字:'))
def ssum(n):
x = 0
if n%2 == 0:
for i in range(2,n+1,2):
x+=1/i
else:
for i in range(1,n+1,2):
x+=1/i
return x
x = ssum(n)
print(x)
一块钱赫赫
发表于 2021-3-13 17:13:00
def jishu(n):
i = 0
s = 0.0
for i in range(1, n + 1,2):
s = 1 / i + s
returns
def oushu(n):
s = 0.0
for i in range(2, n + 1, 2):
s = 1.0 / i + s
returns
n = int(input("请输入一个数字:\n"))
if n % 2 == 0:
s = oushu(n)
else:
s = jishu(n)
print(s)
页:
2
3
4
5
6
7
8
9
10
11
[12]