I'm writing a program that asks simple calculations from the user. The idea is to pass the calculation operator as an argument, it can be addition, subtraction, multiplication or division. I'd like to something like the following work:
def ask(a,b,op):
x = input( a, str(op), b, "=")
return ( x == op(a,b) )
#MAIN:
ask(4, 6, operator.add )
The idea is that this would produce prompt: 4+6=
The problem is of course that str doesn't work that way, and I can't find anything similar in the python documentation or google (it's hard to google, since the word "operator" is so common).