samedi 13 février 2021

Item of a list can not be read by if-statement. What have I done wrong?

Hey guys I need your help! For a school projekt I want to create a flashcard programm in python. I imported a csv-data which include questions and answers and put them in two seperate lists.

with open("List_Questions_Answers.csv", "r") as data:

    Q = []
    A = []

    next(data)

    for line in data:
        q, a = line.split(",")
        Q.append(q)
        A.append(a)

Then I want to ask the user the questions and give feedback if it is right or wrong. But there is the problem: I alway get a "wrong" as feedback even if it is the right answer. When I change the list item with e.g. "1" the program works. I am really frustrated, can someone help me?

guess = input(f"{Q[1]}")
if guess == A[1]:
    print("Right")
else:
    print("Wrong", A[1])

Aucun commentaire:

Enregistrer un commentaire