【发布时间】:2019-02-23 08:57:41
【问题描述】:
我尝试运行一段代码,这行代码出现上述错误:
print("Congratulations! You swapped out a", box3, "for", + str( randomPersuade2 ) + " Dollars. Enjoy!")
box3 保存项目列表中的值
box1,box2,box3,box4, box5 = ["Car", "TV", "DVD", "Overseas Holiday", "Box of chocolates"]
randomPersuade2 是一个变量,它保存来自 random.randint() 函数的值。
randomPersuade2 = random.randint(200,5000)
如标题所述,我得到了错误
TypeError: 一元 + 的操作数类型错误:'str'
我将如何解决这个问题?任何帮助将不胜感激!
【问题讨论】:
-
为什么在
str()调用之前有一个+? -
去掉加号或逗号
标签: python