Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
84 views
in Technique[技术] by (71.8m points)

python - Index error line 13 on my code. list index is out of range


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming you wanted your question_prompts to be a list with 5 elements, then you need commas at the end of each line, like so:

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

Python has implicit concatenation of string literals, so: "a""b" == "ab".

Because of this implicit concatenation, what you have currently is a list with a single element, like this:

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

Obviously not your intention :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...