Create a program that grades a test answers are 1 A 2 C 3 A
Create a program that grades a test. answers are
1.) A 2.) C 3.) A 4.) A 5.) D 6.) B 7.) C 8.) A 9.) C 10.) B 11.) A 12.) D 13.) C 14.) A 15.) D 16.) C 17.) B 18.) B 19.) D 20.) A
The program should store these answers to a list then the program should read the students answer from a text file and store the answers in another list. After the students answers have been read from the file the program should display a message indicating whether they passed or failed. 15 out of 20 is passing. then display the amount of correct answers and number of incorrect answers, with a list showing the question numbers of incorectly answered questions. this is all supposed to be done on python
Solution
answer_key = [\'A\', \'C\', \'A\', \'A\', \'D\', \'B\', \'C\', \'A\', \'C\', \'B\', \'A\', \'D\', \'C\', \'A\', \'D\', \'C\', \'B\', \'B\', \'D\', \'A\'] #correct answers
 answers = [line.strip() for line in open(\"student_answers.txt\", \'r\')] #reading answers from the file. Assuming each answer is stored in each line
 wrong_answers = [] #wrong answers list initiailisation
 correct_answers = 0 #initialise number of correct answers
 for i in range(20): #iterating through the list of answers
     if answer_key[i]==answers[i]: #checking if answer correct
         correct_answers += 1
     else:
         wrong_answers.append(i+1) #adding to wrong answers if answer wrong
 if correct_answers>=15:
     print \"Passed\"
 else:
     print \"Failed\"
#Outputs
 print \"Total Correct Answers: \", correct_answers
 print \"Number of Incorrect Answers: \", len(wrong_answers)
 print \"Wrong Answers: \",
for i in range(len(wrong_answers)):
     print wrong_answers[i],\" \",

