Newton Raphson Method in Python