Okay, so I was playing around and I have an error I don't know how to fix.
def main(): # Constant of correct test answers. CORRECT_ANSWERS = ["A" , "C" , "A" , "A" , "D" , "B" , "C" , "A" , "C" , "B" , "A" , "D" , "C" , "A" , "D" , "C" , "B" , "B" , "D" , "A"] # filling a list with every line, stripped of the \n, from the opened file student_answers = [line.strip('\n') for line in open('test.txt', 'r')] student_correct = 0 incorrect_num = [(index + 1) if CORRECT_ANSWERS[index] != student_answers[index] else (student_correct +1) for index in CORRECT_ANSWERS] print(incorrect_num) main()The error is
Error:Traceback (most recent call last):File "", line 15, in <listcomp>
(student_answers +1) for index in CORRECT_ANSWERS]
TypeError: list indices must be integers or slices, not str
I fixed the student_answers +1 to student_correct +1. I noticed it after but it doesn't change the error.