Discuss / Python / itertools,打卡

itertools,打卡

Topic source

人玉匆花

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

def pi(N):

    natuals = itertools.count(1,2)

    list1 = []

    for i in natuals:

        if i <= 2*N - 1:

            list1.append(i)

        else:

            break

    list1 = deque(list1)

    list2 = []

    for n in range(len(list1)):

        if n % 2 == 0:

            list2.append(4/list1.popleft())

        else:

            list2.append(-4/list1.popleft())

    return sum(list2)

看评论里的大佬,意识到自己代码写的真丑。


  • 1

Reply