Solving math problems with Python