def f(x): return x**3 - 3*x**2 + x + 3 def dicho(a,b,d): if a > b: a,b = b,a while b-a > d: m = (a+b)/2 if f(m) > 0: b = m else: a = m return a,b