Discuss / Python / work

4Neutrino

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

#暂时没想到怎么在这里使用itertools,只能先写了一个没使用的版本

def pi(N): odds = [x for x in range(N * 2) if x % 2 == 1]

sum = 0
for i, n in enumerate(odds):
    sign = 1 if i % 2 == 0 else -1
    sum += sign * 4 / n

return sum

  • 1

Reply