I'm writing an application in Python 3 that processes a lot of mathematical equations. In theory, I'd have to write a different function inside the code each time I need this application. I'd like to enter a function (a mathematical function) from keyboard, to save a lot of time and make this application more versatile.
For example:
def readfunction():
func = input("Type the function you want to solve: ")
return func
def solve(function)
# does stuff
solve(readfunction)
The question is about "interpreting" input so that, say, if I type x+sin(x) each part is recognised as separate to like x is a variable which I can assign a value to (thus creating a new variable that is NOT in the original code), + is an operator and sin is a function from the module math. That way I can manipulate the function as I please.
How would I do that?