def pi(N): result = 0 flag = -1 odds = itertools.count(1,2) nodds = itertools.takewhile(lambda x:x <= 2 * N - 1,odds) for n in nodds: flag = -flag result = result + flag * 4 / n return result
Sign in to make a reply
雨落89757
def pi(N): result = 0 flag = -1 odds = itertools.count(1,2) nodds = itertools.takewhile(lambda x:x <= 2 * N - 1,odds) for n in nodds: flag = -flag result = result + flag * 4 / n return result