I have a code in which the user chooses the function he wants to execute. There is no definite amount of functions as the functions may increase in the future. I am storing the value fetched from the User input into a variable. I want to make the variable callable.
functions = ['add','sub','mul']
a = 10
b = 5
x = input('Choose a function : ')
def add():
print(a+b)
def mul():
print(a*b)
def sub():
print(a-b)
x()
I want the variable 'x' to be called and executed as a function.
x=addThen you can call x as a function.x(1,2)