I\'m doing an exercise that asks for a function that approximates the value of pi using Leibniz\' formula. These are the explanations on Wikipedia:
The Leibniz formula translates directly into Python with no muss or fuss:
>>> steps = 1000000 >>> sum((-1.0)**n / (2.0*n+1.0) for n in reversed(range(steps))) * 4 3.1415916535897934