Tuesday, June 23, 2009

Pi

Hey, we made a Pi program with Python. Syntax is as follows:


x=1
y=3
a=-1
z=int(input("How many calculations? "))
while z>0:
x=x+(a/y)
a=-a
y=y+2
z=z-1
print(4*x)


This uses the following pi formula:


\pi=4(1-\frac{1}{3}+\frac{1}{5}-\frac{1}{7}+\frac{1}{9}-\dots)

No comments:

Post a Comment