I need to make a program that takes user input (expr) of math expression and treats finds the answer. however, we are not allowed to use the eval() function. the assignment states that the only operators we should assume the user will input are: +, -, *, /, %. operands are also assumed to be one-digit integers.
my thinking was to convert operands to integers and make a list of all the operators that could be used. then, use an if statement to see how the operator matches my list.
so far I was able to come up with these lines of code:
operand1 = expr[1]
operator = expr[2]
operand2 = expr[3]
operators = ['+','-','*','/','%']
I did this to index the location of each operand and the operator in the inputted expression. I am stuck here and was hoping someone could give me some help as to how to move forward. the result of the code needs to output the expression entered by the user, as well as the result of the expression. if the second operand of the expression is a 0 and the operator is division, the code outputs 'None'.