Python code for mathematical classes