PYTHON
Driver’s License
The local driver’s license office has asked you to create an application that grades the written portion of the driver’s license. The paper has 20 multiple-choice questions. Here are the correct answers:
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 pass or failed. (A student must correctly answer 15 of the 20 questions to pass.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.
Hey mate, the Python code for above program is provided below with sample output. Do refer the screenshot of the code for proper indentation and error free execution.
SAMPLE TEXT FILE ( that stores student's answers ) -
MAIN PROGRAM -
# list of correct answers
correct_Answers=['A','C','A','A','D','B','C','A','C','B','A','D','C','A','D','C','B','B','D','A']
# opening text file that stores student's answers
txtFile=open("answers.txt")
i=0
marks=0
student_Answers=list()
incorrect_Answers=list()
# reading student's answers from student.txt and storing in separate list
for line in txtFile:
student_Answers.append(line.strip())
# validating the answers in each list and storing question numbers of incorrect answers in separate list
for answer in student_Answers:
if(answer==correct_Answers[i]):
marks=marks+1
else:
incorrect_Answers.append(i+1)
i=i+1
# printing overall result
if(marks>=15):
print("\nResult: Student is Passed!")
else:
print("\nResult: Student is Failed!")
print("\nTotal number of correctly answered questions: ",marks)
print("Total number of incorrectly answered questions: ",(20-marks))
print("List of question numbers answered incorrectly: ",incorrect_Answers)
# closing the file to free up memory space
txtFile.close()
OUTPUT -
Get Answers For Free
Most questions answered within 1 hours.