我输入要获取的销售金额(按输入)乘以定义的营业税(0.08),然后打印总金额(营业税乘以销售金额)。我碰到这个错误。有人知道什么地方可能有问题或有什么建议吗?salesAmount = raw_input (["Insert sale amount here \n"])['Insert sale amount here \n']20.99>>> salesTax = 0.08>>> totalAmount = salesAmount * salesTaxTraceback (most recent call last): File "<pyshell#57>", line 1, in <module> totalAmount = salesAmount * salesTaxTypeError: can't multiply sequence by non-int of type 'float'
3 回答

DIEA
TA贡献1820条经验 获得超3个赞
问题是salesAmount设置为字符串。如果您在python解释器中输入变量,然后按Enter,您将看到输入的值用引号引起来。例如,如果您输入56.95,则会看到:
>>> sales_amount = raw_input("[Insert sale amount]: ")
[Insert sale amount]: 56.95
>>> sales_amount
'56.95'
您需要先将字符串转换为浮点数,然后再乘以营业税。我会留给您找出答案。祝好运!
添加回答
举报
0/150
提交
取消