I was trying to calculate value of pi using this formula:
I had written this code for finding it for a given n:
def pisum(n): sum=3.0 x=2.0 while (n>0): if n%2==1: sum=sum+(4/(x*(x+1)*(x+2))) else : sum=sum-(4/(x*(x+1)*(x+2))) x=x+2 n=n-1 return str(sum) It runs fine for n=0 and n=1 and gives output 3.0, 3.16666666667. But for n=50 the output should be 3.1415907698497954 but it is giving 2.85840923015. Why so much difference? Please help to correct if i had done something wrong.


