May-13-2024, 12:39 PM
Hi,
I am working on a calculator.
I somehow completed it, but i am getting an error.
Unable to figure out.
Help!
Thanks!
I am working on a calculator.
I somehow completed it, but i am getting an error.
Unable to figure out.
Help!
Thanks!
# Add def add (n1, n2): return n1 + n2 # substract def subtract(n1, n2): return n1 - n2 # multiply def multiply (n1, n2): return n1 * n2 # divide def divide (n1, n2): return n1 / n2 operations = {"+" : "add", "-" : "subtract", "*" : "multiply", "/" : "divide" } num1 = int(input("What's the first number?")) for operation in operations: print(operation) sign = input("What do you want to do?") num2 = int(input("What's the new number?")) calculation_function = operations[sign] Answer = calculation_function (num1, num2) print (f"{num1}{sign}{num2} = {Answer}")
Error: Answer = calculation_function (num1, num2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'str' object is not callable
[error]
[/error]