Root Finding Algorithm Python