Python:不支持的操作数';str';和';浮动';在浮子的简单计算中

Python:不支持的操作数';str';和';浮动';在浮子的简单计算中,python,string,Python,String,这里的问题是什么 THREAD = 2.55 bags_value = input('Bags value in gold: ') cloth_price = input('Cloth price in gold: ') dust_price = input('Dust price in gold: ') bags_cost = (2 * THREAD) + 6 * ((2 * dust_price) + 2 * (5 * cloth_price)) profit = bags_value

这里的问题是什么

THREAD = 2.55

bags_value = input('Bags value in gold: ')
cloth_price = input('Cloth price in gold: ')
dust_price = input('Dust price in gold: ')

bags_cost = (2 * THREAD) + 6 * ((2 * dust_price) + 2 * (5 * cloth_price))

profit = bags_value - bags_cost
print(profit)
皮查姆喊道:

TypeError: unsupported operand type(s) for +: 'float' and 'str'
如果从终端执行脚本,也会发生同样的情况


然而,它在ipython下工作得非常完美。wtf

输入
返回
字符串
。您必须强制转换为浮动:

THREAD = 2.55

bags_value = input('Bags value in gold: ')
cloth_price = input('Cloth price in gold: ')
dust_price = input('Dust price in gold: ')

bags_cost = (2 * THREAD) + 6 * ((2 * float(dust_price)) + 2 * (5 * float(cloth_price)))

profit = bags_value - bags_cost
print(profit)

input()
返回字符串。把他们变成花车为什么他被否决了?他提供了所有相关代码和错误消息。这是一个简单的修复,但我认为这正是它的目的。