Z
Z
Zinoks2020-06-23 17:35:55
Python
Zinoks, 2020-06-23 17:35:55

How to fix TypeError: unsupported operand type(s) for -: 'str' and 'str'?

Hello. I am new and just learning python. I tried to make a calculator and got such an error when trying to count on -
Maybe someone knows how to solve this?
Here is the code:
what = input ("Select an action (+ or -):")

a = input("Enter the first number: ")
b = input("Enter the second number: ")

if what == "+":
c = a + b
print("Result: " + c)

elif what == "-":
c = a - b
print("Result: " + c)

else:
print("Invalid operation!")

w3ssqRhAx-M.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-06-23
@Zinoks

c = int(a) + int(b)
c = int(a) - int(b)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question