Find the number of terms required in the Leibniz formula to approximate pi to n significant figures?
<p>I have to find the number of terms required to approximate pi to n significant figures using the sum of the Leibniz series. I have already found the sum and the approximation of pi, but I don't know how to start writing the function that compares sigfigs in the two variables, or even how to determine the number of sigfigs in a given number. Any help would be appreciated, thanks.</p>

<pre><code>sum = 0
for i in range(800001):
    int = ((-1)**i) / (2*i+1)
    sum += int 
print(sum) 
pi = sum*4
</code></pre>

<p>print(pi)</p>

<p>The factor of (-1)**i means that the terms in the series have alternating signs.  Also, the magnitudes of the terms are monotonically decreasing.  One property of such series is that the error you incur by truncating the series is smaller than the smallest term that was included.</p>

python loops pi