-1
num1 = input("Enter your first number: ")
operator = input("Enter +, *, +, or -")
num2 = input("Enter your second number: ")
if operator("+"):
    print(num1 + num2)

Very new to Python and coding in general so please excuse it if the error is very simple.

4
  • operator('+')? operator is a string. And for checking equality use ==. if operator == '+' Commented May 17, 2020 at 5:53
  • num1 is not visible. There is no visible conversion (to int?) for num2. Operator is a variable, not a function, better use ==. Commented May 17, 2020 at 5:54
  • Does this answer your question? TypeError: 'str' object is not callable - Python Commented May 17, 2020 at 5:55
  • @nilleb TypeError is raised because OP is using a str as function. And num1+num2 works fine str supports + but it is used for concatenation. Commented May 17, 2020 at 5:56

1 Answer 1

2

You need to change

if operator("+"):
   print(num1 + num2)

to

if operator == "+":
    print(int(num1) + int(num2))

The operator is a string and to check if a string is equal to a value in python you use ==.
And the num1 and num2 the return from the input as a string so the add them as numbers you need to cast them to int.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.