这很简单,到目前为止我找到的消息都没有处理我的低级问题,但这是我的代码.
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)
我不明白为什么它不受支持?
你不能减去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)
>>> int('2') - int('1')
1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1762 次 |
| 最近记录: |