I am making a game which involves math, and the equations are randomly generated. The operations are stored in a table and numbers are made with math.random, like this:
This might be overkill for your case, but I wanted to add that you could implement the Shunting yard algorithm to convert the expression from infix notation (normal readable math notation) into postfix notation. From there, you could evaluate the postfix expression to get the answer.
Again, might be overkill but it’s a general solution for this type of problem.