我有一个非常奇怪的错误,我不知道是什么。 这是我的代码:
def wordChoice():
theme = themechoice
word = theme[randint(0, len(theme) - 1)]
这是错误:
^{pr2}$我到处找遍了,但什么也没找到。我也是一个新手,如果这是显而易见的事情,我很抱歉。在
编辑:
在我设置主题之前:
def themeChoice():
n = 0
for i in themes:
n += 1
print(str(n) + " - " + i)
themechoice = themesToThemes[themes[int(input("Type the number corresponding to your chosen theme: ")) - 1]]
print (themechoice)
当
theme
为空时,将发生此错误。在在尝试从中随机选择元素之前,请确保} ,而不是用
theme
中确实有元素。另外,考虑使用^{randint
手动生成索引。在相关问题 更多 >
编程相关推荐