since python is language that tries hard to have sensible defaultsits split(method splits on whitespace by default (if you think about itthis is most likely what you would expect as well the result is going to be that expr is list with the values + and each element of the expr list is going to be either an operator or an operand if we get an operand then we embed it in tree node and push it onto the stack if we get an operatoron the other handthen we embed the operator into tree node and pop its two operands into the node' left and right children here we have to take care to ensure that the first pop goes into the right childotherwise we will have problems with subtraction and division here is the code to build the treefor term in exprif term in "+-*/"node treenode(termnode right stack pop(node left stack pop(elsenode treenode(int(term)stack push(nodenotice that we perform conversion from string to int in the case of an operand you could use float(insteadif you wanted to support floating point operands at the end of this operationwe should have one single element in the stackand that holds the full tree we may now want to be able to evaluate the expression we build the following little function to help usdef calc(node)if node data is "+"return calc(node leftcalc(node rightelif node data is "-"return calc(node leftcalc(node rightelif node data is "*"return calc(node leftcalc(node rightelif node data is "/"return calc(node leftcalc(node rightelsereturn node data