I'm writing a code in Python which can be used to solve equations. The user must first input a code via a raw_input(), which will then be used to calculate y for every x in a loop with eval(), like so:
#some imports (math) and other irrelevant code
Code = raw_input('please enter your equation')
Low = raw_input('please enter the lowest number in the domain')
High = raw_input('please enter the highest number in the domain')
X = Low
While X <= High:
Y = eval(code)
#complicated code to solve equation
X += #number depending on the amount of decimals
#simpler code to print the result
The problem is that parsing the input code using eval() for every loop is extremely slow. Is there a way to parse the code only once and then use it as a function in the rest of the program?