def bisec(a,b):
# The user should enter values of x = a and x = b in the program that calls this function
# x = a and x = b should be such that f(a)*f(b) < 0
# Also, a should be less than b
while (f(a)*f(b) > 0 or a >= b):
print("enter values of x = a and x = b such that f(a)*f(b) < 0")
a = eval(input("First, enter a value for a "))
b = eval(input("Next, enter a value for b "))
tol = 0.0000001
diff = 1.0
while diff >= tol:
c = (a + b)/2
# c is the midpoint of the interval [a, b]
if (f(a)*f(c)) == 0:
return c
elif (f(a)*f(c)) < 0:
b = c
else:
a = c
diff = b - a
c = (a + b)/2
return c