Hi! I am trying to do this multiple choice quiz and I keep getting this error:
Traceback (most recent call last):
File “C:/Users/ccerv/PycharmProjects/Microsoft_Python Beginners/Multiple Choice quiz.py”, line 11, in
Question(question_prompts[1], “c”),
IndexError: list index out of range
Here is my code ->
class Question:
def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
from Class_quiz import Question
question_prompts = [
"De que color son las manzanas?\na)Rojas\nb)Azules\nc)Moradas\n\n"
"De que color son los bananos?\na)Azul\nb)Verde\nc)Amarillo\n\n"
"De que color son las fresas?\na)Lila\nb)Anaranjado\nc)Rojo\n\n"
]
questions = [
Question(question_prompts[0], "a"),
Question(question_prompts[1], "c"),
Question(question_prompts[2], "c"),
]
def run_test(questions):
score = 0
for question in questions:
answer = input(question_prompts)
if answer == question.answer:
score += 1
print("You got" + str(score) + "/" + str(len(questions)) + "correct")
run_test(questions)