Python:乘法时出现TypeError

ushi

我正在尝试完成我的课程,目前正在尝试提供产品收据,这是我认为是问题所在的编码部分:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

遍历 argv 时出现 TypeError (Python)

转换 JSON 时出现 Python TypeError

在 Python 中运行 bfs 算法代码时出现 TypeError

在 Python 中对编码的 BeautifulSoup 执行 replace() 时出现 TypeError

Python:使用 os.environ.get 时出现 TypeError

在Python中导入Color-Science模块时出现“ TypeError”

Python-生成日期列表时出现TypeError

Python:在字符串中搜索时出现TypeError

在 python 中使用 SQLite3 时出现 TypeError

尝试运行 python 代码时出现 TypeError

Python:尝试使用我打开的文件的内容时出现 TypeError

函数乘法时的Python递归错误

Python在乘法时产生奇怪的小数

提交表单时出现TypeError

Python2:在检查字典值时出现TypeError

使用 reticulate 包从 Python peakutils 包调用函数时出现 TypeError

在Python 3中使用子字符串函数时出现TypeError

在 python 中传递和设置命令行参数时出现 TypeError

ROS2,将自定义消息发布到 Topic 时出现 TypeError (python)

尝试通过索引获取元组中的对象时,Python 中出现“TypeError: 'tuple' object is not callable”错误

在 PHPUnit 中模拟接口时出现 TypeError

调用 React 函数时出现 TypeError 异常

尝试遍历 Map 元素时出现 TypeError

使用 Scrapy View 时出现 TypeError

运行Django测试时出现TypeError

为什么在构建dict()时出现TypeError?

拆分 Json 数据时出现 TypeError?

使用pydbgen模块时出现TypeError

使用keras功能模型时出现TypeError