# pi.py -rw-r--r-- 430 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from math import pi
from math import log10

n_max = 100000000

half_pi = 1
for n in range(1,n_max+1):
    half_pi *= (2.0*n/((2*n)-1))*(2.0*n/((2*n)+1))
    if (n>=10) and (log10(n) % 1 == 0.0):
        full_pi = half_pi*2
        print((
            '(n=%9d) pi=%.10f math.pi=%.10f diff=%.5f%%' % (
                n,
                full_pi,
                pi,
                abs(100*(full_pi-pi)/pi)
            )
        ))