I have just started learning python and to test if I can do loops correctly I tried to calculate pi through the wallis product.
The code I wrote was like this:
pi=[1]i=0while i<100: i=i+1 pi=pi+[4*i**2/(4*i**2-1)]print(pi)x=1for y in pi: x=x*y print(x*2)For some reason this is giving a very very bad approximation of pi and I don't know why. With 100 iterations it should definitely not give 3.13And even if i increase the number of iterations the improvement is minimal. I know it's a very basic code but I'm just learning this language and I don't see if the mistake is on the floating point error or in my code itself.