Python:乘法时的`TypeError`

时间:2017-02-10 13:11:09

标签: python typeerror

我正在努力完成课程作业,而我目前正在尝试制作产品收据,这是编码的一部分,我认为是问题:

if ProductNumberStr==order:
        item_in_productslist=True
        print()
        print("PRODUCT FOUND:")
        print()
        print("Product Number: ",ProductNumberStr)
        print("Description: ",DescriptionStr)
        print("Price per item: ",price)
        print("Quantity of item ordered: ",quantity)
        print("Total cost of order: ",price*quantity)
        print()
        print("*************************************")
        print()
        ReceiptStr+=ProductNumberStr+" "+DescriptionStr+
                    " "+str(quantity)+" "+str(price)+" "+str(price)*str(quantity)

当我尝试打印收据'发生错误时,我已尝试修复错误,但作为初学者,我似乎无法弄清楚如何修复错误。 这就是错误说明的内容:

  

* ReceiptStr + = ProductNumberStr +" &#34 + + DescriptionStr" &#34 + STR(数量)+" &#34 + STR(价格)+" " + str(价格) str(数量)TypeError:不能相乘   序列由非int类型' str'

如果有人能提供帮助,我真的很感激!

1 个答案:

答案 0 :(得分:2)

可能是:

<div id="map-div" class="map-style" data-tap-disabled="true">

str(x)是string类型,因此没有乘法运算的操作:str(x)* str(y)。我想你想要做的是乘以de值并将结果用作字符串。所以,请参阅上面的语法