Reference no: EM132356985
Question
Define a recursive function that finds the result of an arithmetic string. The given string will contain numbers, operators (+, -, *, /), and possibly spaces. You should compute the result respecting order of operations. The function should return an int if the string contains only whole numbers and does not use division. Otherwise, the function should return a float. You do not need to consider division by zero in your solution.
Your solution must use recursion in order to receive points.
Parameter(s):
A string containing numbers, operators (+, -, *, /), and possibly spaces. Return Value: An int or a float of the resulting value.
Example(s):
>>> print(solve_eq("1 + 1"))
2
>>> print(solve_eq("1 + 5 * 4"))
21
>>> print(solve_eq("1.0 + 5 * 4")) 21.0
>>> print(solve_eq("1 - 10 * 5 / 80")) 0.375