TOL = 1.e-4

def bisect(g, z1, z2, tol):
    while abs(z2 - z1) > tol:
        zm = (z1 + z2)/2
        if g(z1)*g(zm) > 0:
            z1 = zm
        else:
            z2 = zm
    return (z1+z2)/2

def gg(z):
    return z**5 - 3.

z = bisect(gg, 0., 4., TOL)

z0 = 3**0.2
print('z =', z, ' gg =', gg(z), ' error =', (z-z0)/z0)
