I am writing a python script that needs to take an equation from a user in the form of something like this
z=x^2+3x+9 +y^3 or z =cos(pi/2+x) + 2sin(y)
and evaluate the function at runtime over many values for x and y. How would I go about using the input given by a user as a function? Meaning I would like to be able to do something like this:
input = input("please input 3 variable function.")
function = evaluate_function(input)
for x and y:
result = evaluate function
return result
Is something like this possible? I have looked around and the closed thing I have found to what I want to do seems to be this (How to process user supplied formulas?), but it is only talking about evaluating for a single value of x and z not iterating over many values. Any help would be greatly appreciated.
Update: As suggested below I found this (http://lybniz2.sourceforge.net/safeeval.html) about using eval() which seems to be pretty much what I want to do