Python:乘法中的“TypeError”

2024-10-01 15:34:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力完成我的课程,目前我正在努力制作产品收据,以下是我认为问题所在的编码部分:

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”时,出现了一个错误,我尝试过修复它,但是作为一个初学者,我似乎不知道如何修复这个错误。 错误说明如下:

*ReceiptStr+=ProductNumberStr+" "+DescriptionStr+" "+str(quantity)+" "+str(price)+" "+str(price)str(quantity) TypeError: can't multiply sequence by non-int of type 'str'

如果有人能帮忙,我会非常感激的!你知道吗


Tags: of编码产品错误orderitempricequantity
1条回答
网友
1楼 · 发布于 2024-10-01 15:34:19

可能是:

str(price*quantity)

str(x)是string类型,因此不需要对字符串进行乘法操作:str(x)*str(y)。我认为,你要做的是将de值相乘,并将结果用作字符串。所以,请看上面的语法

相关问题 更多 >

    热门问题