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"时,发生了错误,我试图修复它,但作为初学者,我似乎无法弄清楚如何修复错误。这是错误所指出的:

*收据Str+=ProductNumberStr+" "+DescriptionStr+" "+str(quantity(+" "+

str(price(+" "+str(price(str(quantity( 类型错误: 不能乘法 按类型为"str"的非整数排序

如果有人能帮忙,我将不胜感激!

可能是:

str(price*quantity)

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

最新更新