Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在我的代码上索引错误行13。列表索引超出范围_Python_Index Error - Fatal编程技术网

Python 在我的代码上索引错误行13。列表索引超出范围

Python 在我的代码上索引错误行13。列表索引超出范围,python,index-error,Python,Index Error,我是python的新手,试图编写关于ABC测验的代码,这是一个关于YT的教程,但是当我运行它时,它显示了一个错误。第13行,在 问题(问题[1],“a”), 索引器:列表索引超出范围 这是密码 question_prompts = [ "How many time does Sebastian Vettel win a World Driver Championship on F1?\n(a). never\n(b). 2x\n(c). 5x\n(d). 4x" "

我是python的新手,试图编写关于ABC测验的代码,这是一个关于YT的教程,但是当我运行它时,它显示了一个错误。第13行,在 问题(问题[1],“a”), 索引器:列表索引超出范围

这是密码


question_prompts = [
"How many time does Sebastian Vettel win a World Driver Championship on F1?\n(a). never\n(b). 2x\n(c). 5x\n(d). 4x"
"When was the last time Michael Schumacher won f1 WDC?\n(a). year 2004\n(b). year 2011\n(c). year 2006\n(d). year 2005"
"Track that held an F1 Grand Prix more than any circuits\n(a). Monza\n(b). Silverstone\n(c). Monaco\n(d). Spa"
"What was the opening Grand Prix of the season before Australia become the season opener?\n(a.)Bahrain\n(b). China\n(c). Abu Dhabi\n(d). Spain"
"Who is the only driver that had 5 WDC until now?\n(a). Lewis Hamilton\n(b). Alain Prost\n(c). Juan Manuel Fangio\n(d). Aryton Senna"
]

questions = [
    Question(question_prompts[0], "d"),
    Question(question_prompts[1], "a"),
    Question(question_prompts[2], "a"),
    Question(question_prompts[3], "a"),
    Question(question_prompts[4], "c"),
]

def run_test(questions):
    score = 0
    for question in questions:
        answer = input(question_prompts)
        if answer == question.answer:
            score += 1

            print("Hey you got " + str(score) + " / " + str(len(questions)) + " Correct")

假设您希望您的
问题\u提示是一个包含5个元素的列表,那么您需要在每行末尾加逗号,如下所示:

question_prompts = [
    "How many time does Sebastian Vettel win a World Driver Championship on F1?\n(a). never\n(b). 2x\n(c). 5x\n(d). 4x",
    "When was the last time Michael Schumacher won f1 WDC?\n(a). year 2004\n(b). year 2011\n(c). year 2006\n(d). year 2005",
    "Track that held an F1 Grand Prix more than any circuits\n(a). Monza\n(b). Silverstone\n(c). Monaco\n(d). Spa",
    "What was the opening Grand Prix of the season before Australia become the season opener?\n(a.)Bahrain\n(b). China\n(c). Abu Dhabi\n(d). Spain",
    "Who is the only driver that had 5 WDC until now?\n(a). Lewis Hamilton\n(b). Alain Prost\n(c). Juan Manuel Fangio\n(d). Aryton Senna",
]
Python具有字符串文本的隐式连接,因此:
“a”“b”==“ab”

由于这种隐式连接,您当前拥有的是一个包含单个元素的列表,如下所示:

question_prompts = [
    "How many time does Sebastian Vettel win a World Driver Championship on F1?\n(a). never\n(b). 2x\n(c). 5x\n(d). 4xWhen was the last time Michael Schumacher won f1 WDC?\n(a). year 2004\n(b). year 2011\n(c). year 2006\n(d). year 2005Track that held an F1 Grand Prix more than any circuits\n(a). Monza\n(b). Silverstone\n(c). Monaco\n(d). SpaWhat was the opening Grand Prix of the season before Australia become the season opener?\n(a.)Bahrain\n(b). China\n(c). Abu Dhabi\n(d). SpainWho is the only driver that had 5 WDC until now?\n(a). Lewis Hamilton\n(b). Alain Prost\n(c). Juan Manuel Fangio\n(d). Aryton Senna"
]

显然不是您的意图:)

您在问题提示中的每个问题后面都缺少逗号