how to solve mathematical expression in python