TypeError:不支持的操作数类型 - :'str'和'str'Simpleton

Loo*_*unt 2 python python-3.x

这很简单,到目前为止我找到的消息都没有处理我的低级问题,但这是我的代码.

name=input("What is your name?")
weight=input("How much do you weigh?")
target=input("What would you like to weigh?")
loss=weight-target
print("So...",name,'You need to lose',loss,"pounds!")
print("\n\nPress enter key to scram!")
Run Code Online (Sandbox Code Playgroud)

错误:

Traceback (most recent call last):
  File "/Users/davebrown/Desktop/Pract.py", line 7, in <module>
    loss=weight-target
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Run Code Online (Sandbox Code Playgroud)

我不明白为什么它不受支持?

fal*_*tru 5

你不能减去str对象.(input在Python 3.x中返回str对象,与inputPython 2.x 不同)

>>> '2' - '1'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Run Code Online (Sandbox Code Playgroud)

将它们转换为intfloat首先.

>>> int('2') - int('1')
1
Run Code Online (Sandbox Code Playgroud)