补充详细讲解
Topic source交作业,顺便学习别人的思路
def pi(N):
odds = itertools.count(1,2)
o = itertools.takewhile(lambda x: x <= 2 * N - 1, odds)
flag = 0
s = 0
for i in o:
if flag == 0:
s = s + 4 / i
flag = 1
else :
s = s - 4 / i
flag = 0
return s
- 1
gd83594394
Python-进阶-itertools模块小结 http://www.wklken.me/posts/2013/08/20/python-extra-itertools.html#itertoolscountstart0-step1