Skip to content

Instantly share code, notes, and snippets.

@supritashankar
Created February 3, 2013 04:36
Show Gist options
  • Save supritashankar/4700562 to your computer and use it in GitHub Desktop.
Save supritashankar/4700562 to your computer and use it in GitHub Desktop.
Leibniz formula for pi
from decimal import *
getcontext().prec = 15
t=[]
for i in range(int(raw_input())):
t.append(raw_input())
for i in range(len(t)):
o=t[i]
l=[]
for j in range(int(o)):
p=Decimal((2*j) + 1)
m=Decimal(1/p)
if j%2 != 0:
m=m*(-1)
l.append(m)
print sum(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment