Jan-22-2019, 11:38 PM
I copied in the student_answers list again to make it easier.
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_answers = ["B", "C", "A", "A", "A", "B", "A", "A", "C", "C", "A", "D", "C", "A", "A", "C", "B", "B", "D", "D"] student_correct = [(index + 1) for index in range(len(CORRECT_ANSWERS)) if CORRECT_ANSWERS[index] == student_answers[index]] incorrect_num = [(index + 1) for index in range(len(CORRECT_ANSWERS)) if CORRECT_ANSWERS[index] != student_answers[index]] print(incorrect_num) print(len(student_correct)) print("Passed" if (len(student_correct) / len(student_answers)) >= .75 else print("Failed")) main()I don't know where the None is coming from in the output though.
Output:[1, 5, 7, 10, 15, 20]
14
Failed
None