def function_factory(x,y,o):
return lambda: eval(str(x)+o+str(y))
from operator import add, sub, mul, truediv, mod
def function_factory(x,y,o):
return lambda: {"+": add, "-": sub, "*": mul, "/": truediv, "%": mod}[o](x, y)
def naughty_function_factory(x,y,o):
return lambda: eval("{} {} {}".format(x, o, y))
def function_factory(x,y,o):
def f():
return eval('{}{}{}'.format(x,o,y))
return f
def function_factory(x, y, operator):
def my_function():
return eval(f"{x} {operator} {y}")
return my_function
def function_factory(x,y,o):
return lambda: eval(f'{x}{o}{y}')
def function_factory(x,y,o):
a = str(x)
b = str(y)
return lambda: eval(a+o+b)
def function_factory(x,y,o):
def func():
return eval(str(x)+o+str(y))
return func
def function_factory(x,y,o):
operations = {'+':x + y,
'-':x - y,
'*':x * y,
'/':x / y,
'%':x % y}
def evaluate():
return operations[o]
return evaluate
def function_factory(x,y,o):
def add():
return x + y
def subtract():
return x - y
def multiply():
return x * y
def divide():
return x / y
def reminder():
return x % y
operations = {'+':add,
'-':subtract,
'*':multiply,
'/':divide,
'%':reminder}
return operations[o]
def function_factory(x,y,o):
operations = {'+':x + y,
'-':x - y,
'*':x * y,
'/':x / y,
'%':x % y}
def calc_function():
return operations[o]
return calc_function
景越Python基础训练营QQ群
欢迎各位同学加群讨论,一起学习,共同成长!