我正在尝试完成我的课程,目前正在尝试提供产品收据,这是我认为是问题所在的编码部分:
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(数量)+“” + str(价格)+“” + str(价格)str(数量)TypeError:无法将序列乘以'str类型的非整数'
如果有人可以帮忙,我将不胜感激!
可能是:
str(price*quantity)
str(x)的类型为字符串,因此不存在将字符串相乘的操作:str(x)* str(y)。我想您想做的就是将de值相乘并将结果用作字符串。因此,请参见上面的语法
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句