Discuss / Python / 作业

作业

Topic source

一度剑心

#1 Created at ... [Delete] [Delete and Lock User]

def pi(N):

    ns = itertools.count(1, 2)

    nc=itertools.takewhile(lambda x: x <= 2*N, ns)

    sum=0

    L=list(nc)

    for i in range(N):

      if i%2:

        sum+=-4/L[i]

      else:

        sum+=4/L[i]

    return sum


  • 1

Reply