我一直在为我设计一个学习数学问题的程序。不,在某种程度上,一切都是完美的。问题是显示问题。我这样做是为了根据你选择的等级使用特定的数字。我将给出与问题相关的代码:
Lvlonenumbers =list(range(1, 51))
if Level == 'Lvl.1':
NumberList = Lvlonenumbers
NumberOne =random.choice(NumberList)
NumberTwo =random.choice(NumberList)
Answer =NumberOne + NumberTwo
print(str(NumberOne) + '+' + str(NumberTwo) + '=' + variable)
当程序去执行print函数时,它会说cannot convert object'list'隐式转换成str。我不明白为什么会这样。我以前从未见过这种错误。在
不能将列表添加到字符串中,因为Python不知道如何将列表转换为字符串。这是你的基本问题。您可以使用一个join来预先对其进行转换,例如:
''.join(variable)
:我还根据python style guide更改了变量名。在
相关问题 更多 >
编程相关推荐