I have the following code (probably self-explanatory):
def main():
print("Please input 2 numbers to operate on: ")
value1 = int(input())
value2 = int(input())
print("Please input an operator: ")
operator = str(input())
result ={
'+': lambda x, y: x+y,
'-': lambda x, y: x-y,
'*': lambda x, y: x*y,
'/': lambda x, y: x/y
}.get(operator(value1, value2), "Error")
print(result)
if __name__ == "__main__":
main()
But I get the error:
Please input 2 numbers to operate on:
4
4
Please input an operator:
*
Traceback (most recent call last):
File "C:\Users\Megapoort\source\repos\Python switch function\Python_switch_function.py", line 17, in <module>
main()
File "C:\Users\Megapoort\source\repos\Python switch function\Python_switch_function.py", line 13, in main
}.get(operator(value1, value2), "Error")
TypeError: 'str' object is not callable
I dont really understand what I did wrong here.