linfo2335-programming-parad.../project-3/regex/code/code85.py

18 lines
465 B
Python

def approx_pi(i):
if i == 0:
return 4
print(4)
else:
if i == 1:
return 2.666666666
else:
if i == 2:
return 3.46666666
else:
if i == 3:
return 2.8952381
else:
pi = 0
for j in range(i+1) :
pi += (((-1)**j) / ((2*j)+1))
return(4*pi)