Nilakantha

Calculate Pi using Nilakantha's series
from decimal import * import sys getcontext.prec = 40 c = 0 s = Decimal(1); pi = Decimal(3); n = int(sys.argv[1]) for i in range(2, n * 2, 2): pi = pi + s * (Decimal(4) / (Decimal(i) * (Decimal(i) + Decimal(1)) * (Decimal(i) + Decimal(2)))) s = -1 * s    c = c + 1 print c, (pi)
 * 1) !/usr/bin/python