Reputation: 1
Below I have posted a picture of the task which I want to solve. There I need to show 15 approximations of this number list (here is the equation):
So far I have the following code:
p=3
for i in range(15):
if (i+1) %2==0:
p= p-(4/((2+2*i)*(3+2*i)*(4+2*i)))
else:
p= p+(4/((2+2*i)*(3+2*i)*(4+2*i)))
print(p)
However it just gives me the 15th result. Can someone please help me?
Upvotes: 0
Views: 364
Reputation: 1501
You are using a variable that is uptaded at every iteration. You need to store the desired values in a list or something, like:
p=3
my_pis = []
for i in range(15):
if (i+1) %2==0:
p= p-(4/((2+2*i)*(3+2*i)*(4+2*i)))
else:
p= p+(4/((2+2*i)*(3+2*i)*(4+2*i)))
my_pis.append(p)
print(my_pis)
Upvotes: 1