def pi(N):
ns = itertools.count(1, 2)
nc=itertools.takewhile(lambda x: x <= 2*N, ns)
sum=0
L=list(nc)
a=[-4/L[i] if i%2 else 4/L[i] for i in range(N)]
for i in a:
sum+=i
return sum
Sign in to make a reply
一度剑心
def pi(N):
ns = itertools.count(1, 2)
nc=itertools.takewhile(lambda x: x <= 2*N, ns)
sum=0
L=list(nc)
a=[-4/L[i] if i%2 else 4/L[i] for i in range(N)]
for i in a:
sum+=i
return sum