I am trying to implement a calculator operation using dictionary, instead of if-else conditions. However instead of running only the one required function, all the functions defined in the dictionary is run. Following is the code:\n
def add(a,b):
print(f'Sum of {a} and {b} is:',(a+b))
def diff(a,b):
print(f'Difference of {a} and {b} is:',(a-b))
def prod(a,b):
print(f'Product of {a} and {b} is:',(a*b))
n1 = 5
n2 = 3
op = int(input("Enter the command for operation (1-3): "))
dic = {1: add(n1,n2), 2: diff(n1,n2), 3: prod(n1,n2)}
dic[op]
If i am entering 3 the expected output is 15 as only the value prod(n1,n2) should be triggered for the key 3. However i am getting the result of all the three functions as output no matter what my input is (in the range of 1-3). Why is it happening and how can i ensure that only one function is called, as per my input ?