Please answer this question. hat ale gieater than the number n 7. Driver\'s Lice
ID: 3735059 • Letter: P
Question
Please answer this question.
hat ale gieater than the number n 7. Driver's License Exam The local driver's license office has asked you to create an application that grades the writ ten portion of the driver's license exam. The exam has 20 multiple-choice questions. Here are the correct answers: 1. A 2. 3. A 4. A 5. D 8. A 9, C 10. B 13. 18. 14. A19. D 15. D20. A Your program should store these correct answers in a list. The program should read the student's answers for each of the 20 questions from a text file and store the answers in another list. (Create your own text file to test the application.) After the student's answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question num- bers of the incorrectly answered questions.Explanation / Answer
def main():
correct_answers = ['A','C','A','A','D','B','C','A','C','B','A','D','C','A','D','C','B','B','D','A']
student_answers = []
with open('student_answers.txt','r') as ins:
student_answers = ins.read().splitlines()
processing(correct_answers,student_answers)
def processing(correct_answers,student_answers):
correct = 0.0
wrong = 0
percentage = 0.0
listCorrect = []
listWrong = []
try:
for i in range(len(correct_answers)):
if len(student_answers[i]) == 1:
if student_answers[i].upper() >= 'A' and student_answers[i].upper() <= 'Z':
if(correct_answers[i]==student_answers[i].upper()):
correct = correct + 1
listCorrect.append(i)
else:
wrong = wrong + 1
listWrong.append(i)
else:
raise ValueError
else:
raise IOError
output(correct,wrong,listCorrect,listWrong)
except IOError:
print("Only Characters A-Z is allowed")
except ValueError:
print("Numeric input is not allowed")
def output(correct,wrong,listCorrect,listWrong):
if correct >= 15:
print("You have passed the test")
else:
print("You have failed the test")
print('You correctly answered %d questions' %(correct))
print('You incorrectly answered %d questions' %(wrong))
print('You wrongly answered : %s ' %(listWrong))
main()