Bisection method in python