Calcpi

Calculate pi to any given number of digits
import sys from decimal import * D = Decimal getcontext.prec = int(sys.argv[1]) a = n = D(1) g, z, half = 1 / D(2).sqrt, D(0.25), D(0.5) for i in range(18): x = [(a + g) * half, (a * g).sqrt] var = x[0] - a    z -= var * var * n     n += n     a, g = x print(a * a / z)
 * 1) !/usr/bin/python3