Это мой код.
n1, n2 = (int(input("Enter number: ")) for _ in range(2))
print("Select Your Choice: ")
print(" 1: Addition",
"2: Substraction",
"3: Multiplication",
"4: Division")
choice = int(input())
switcher = {
1: "Addition",
2: "Substraction",
3: "Multiplication",
4: "Division",
}
def addition(n1,n2):
n1 += n2
return n1
def substraction(n1,n2):
n1 -= n2
return n1
def multiplication(n1,n2):
n1 *= n2
return n1
def division(n1,n2):
n1 /= n2
return n1
def calculator(choice,n1,n2):
return switcher.get(choice,"Invalid")(n1,n2)
print(calculator(choice,n1,n2))
Я получил ошибку ниже.
> Traceback (most recent call last):
> simple calculator with dictionary.py", line 36, in <module>
> print(calculator(choice,n1,n2))
> simple calculator with dictionary.py", line 34, in calculator
> > return switcher.get(choice,"Invalid")(n1,n2)
> TypeError: 'str' object is not callable
Может ли кто-нибудь решить эту ошибку?