I cannot determine my logic error,
Code:
import math
repeat = "y"
factor = [5]
def findFactor():
res = factor[0]
factor[0] += 2
print(res)
return res
while (repeat == "y"):
tol = float(input("Please enter the tolerance: "))
z = 6/math.sqrt(3)
print(z)
num1 = 1
num2 = num1 - (1/3)
i = 2
diff = 999
while math.fabs(diff) > tol:
diff = (z *num2) - (z * num1)
print("Num 1", (z *num1), " Num 2", (z *num2))
print("Pi: ", (z * num2))
num1 = num2
add = (-1)**i/(3**i * findFactor())
print(add)
num2 = num2 + add
i += 1
print("Diff", diff)
print("We got: ", z * num2, " for pi")
repeat = input("Continue? (Y/N)").lower()
It seems to work in the start of the execuation and then just way undershoots pi.