Python 2.7 大学教师;我不理解错误

Python 2.7 大学教师;我不理解错误,python-2.7,Python 2.7,我试图做一个程序,我得到了这个错误 Traceback (most recent call last): File "E:\MyAi.py", line 27, in <module> ask = raw_input(statements[randint(0,len(answers) - 1)]) IndexError: list index out of range 为什么我的代码会导致这种情况?我不明白为什么。你可能是有意这么做的: ask = raw_

我试图做一个程序,我得到了这个错误

Traceback (most recent call last):
    File "E:\MyAi.py", line 27, in <module>
        ask = raw_input(statements[randint(0,len(answers) - 1)])
IndexError: list index out of range

为什么我的代码会导致这种情况?我不明白为什么。

你可能是有意这么做的:

ask = raw_input(statements[randint(0,len(statements) - 1)])
还有:

ask = raw_input(questions[randint(0,len(questions) - 1)])

否则,如果
answers
比您的其他列表大,您就有可能得到您得到的错误。

这不是您的完整代码。展示你如何定义你的变量。哦,是的!谢谢我只是忘了为长度函数设置正确的列表。
ask = raw_input(questions[randint(0,len(questions) - 1)])