Python code for numerical analysis