Index error in Python

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”, 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")


The list question_prompts has no commas separating each element. To Python, this means the list only has one long string item. So question_prompts[0] works, but question_prompts[1] does not exist and it throws an IndexError.

1 Like

Thank you so much!! Is working now!