What I'm trying to do is ask the user for a type of math operator(Not sure if I used the correct term. I'm new to python.), and use that in place of a math operator in an equation.
Here I tried:
math_thing = int(input('Enter a type of math operator(/,*,+,etc.,)'))
result = 12{0}4.format(math_thing)
print(result)
I was expecting it to ask for a sign, and perform the equation(I was going to add checks to see if it was valid), but what happened was it gave me the error SyntaxError: invalid syntax.
I don't really know any other way to do it, and when I looked I thought the .format thing might only work for strings, but I'm not sure.
It is not a generally good idea to use
evalin python, because the user of the program could input malicious code. So make sure only trusted users are using this program on your computer. Also I got rid ofinton theinputfunction as it is not needed:Output (when input is
*):All that
evaldoes is take a string (astrobject) of python code and run it.Please do keep in mind though that you should never use a program of this type using
evalon any system that you are exposing to the internet, because that would make it so anybody any where could run python code on your computer, potentially malicious code.