I want to make a user input an equation that I can work with in Python. How can I modify the raw_input formula that allows me to do this?
Currently, I have this in my code:
consts = list()
nconst = int(input("How many constraints would you like to add? "))
for i in range(nconst):
const = input("Constraint " + str(i+1) + ": ")
consts.append(const)
My constraints are the equations that I want the user to input. I want the equations to be in the format of <=.
I tried using parsers, so I tried a test case of using a parser and I ended up with this code.
import parser
formula = "x^2"
code = parser.expr(formula).compile()
from math import sin
x = 10
print(eval(code))
However, when I ran the code, Python gave me an answer of 8 when the answer is supposed to be 100. Is there a problem also with the parser code that I used?
Any help will be appreciated!