import math
term = ['math.sqrt', 'math.pi', 'math.sin', 'math.cos', 'math.tan',
'math.log', 'math.log', 'math.pow', 'math.cosh', 'math.sinh',
'math.tanh', 'math.sqrt', 'math.pi', 'math.radians',
'math.e','math.radians']
replace = ['√', 'π', 'sin', 'cos', 'tan', 'log', 'ln', 'pow', 'cosh',
'sinh', 'tanh', 'sqrt', 'pi', 'radians', 'e', 'rad']
equation = input('')
for word in replace:
equation = equation.replace(word, term[replace.index(word)])
I am trying to evaluate only the calculations in 'equation' that are also found in the 'term' and afterwards replace the values that we found in 'equation'
Ex. input: x + 5 - sqrt(4) = 9
then my program will replace sqrt(4) with math.sqrt(4)
then it should calculate math.sqrt(4); so math.sqrt(4) = 2
and lastly replace the 2 with sqrt(4) in 'equation'; so, equation = x + 5 - 2 = 9