这非常简单,到目前为止我发现的消息都没有处理我的低级问题,但这是我的代码。
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!")
错误:
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'
我不明白为什么它不受支持?
最佳答案
您不能减去 str
对象。 (与 Python 2.x 中的 input
不同,Python 3.x 中的 input
返回 str
对象)
>>> '2' - '1'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'str'
>>> int('2') - int('1')
1
关于python - 类型错误 : unsupported operand type(s) for -: 'str' and 'str' Simpleton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20595125/