I have to create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. The program I created produces more than the 20 questions. I am new to Python and I do not know what I am doing wrong

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I have to create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. The program I created produces more than the 20 questions. I am new to Python and I do not know what I am doing wrong

1 def main() :
try:
answerkey
3D ['"В', "D', "А', "А', "с", "А', "В', "А', "С', "D', 'B', 'C',1
4
'D'
'A', 'D', 'C', 'c', 'B', 'D', 'A']
index = 0
numCorrect = 0
answer_file = open('studentanswers.txt', 'r')
6.
7
9.
studentExam = answer_file.readline ()
10
11
12
13
14
print ('Correct\tYour\tStatus\nAns.\tAns.\n-
while studentExam != "":
problem_number = index + 1
studentExam = studentExam.rstrip("\n")
-\n')
15
16
17
18
19
20
21
studentExam = answer_file.readline()
for answerLine, studentLine in zip (answerKey, studentExam):
answer = answerLine.split()
studentAnswer = studentLine.split()
if studentAnswer != answer:
print( 'You got that question number', index + 1, 'wrong\n_the correct answer was
index += 1
22
23
, answer, 'but you answered'
24
25
26
27
else:
numCorrect += 1
index += 1
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
grade
= int((numCorrect / 20) * 100)
print (' The number of correctly answered questions: ', numCorrect)
print (' The number of incorrectly answered questions: '
20 - numCorrect)
print (' Your grade is', grade, %')
if grade <= 75:
print (' You have not passed ')
else:
print (' Congrats you have passed ')
except I0Error:
print("The file could not be found")
except IndexError:
print ("There was an indexing error")
except:
print ("An error occurred")
4
45
46
47 main()
48
ON 00 O o
Transcribed Image Text:1 def main() : try: answerkey 3D ['"В', "D', "А', "А', "с", "А', "В', "А', "С', "D', 'B', 'C',1 4 'D' 'A', 'D', 'C', 'c', 'B', 'D', 'A'] index = 0 numCorrect = 0 answer_file = open('studentanswers.txt', 'r') 6. 7 9. studentExam = answer_file.readline () 10 11 12 13 14 print ('Correct\tYour\tStatus\nAns.\tAns.\n- while studentExam != "": problem_number = index + 1 studentExam = studentExam.rstrip("\n") -\n') 15 16 17 18 19 20 21 studentExam = answer_file.readline() for answerLine, studentLine in zip (answerKey, studentExam): answer = answerLine.split() studentAnswer = studentLine.split() if studentAnswer != answer: print( 'You got that question number', index + 1, 'wrong\n_the correct answer was index += 1 22 23 , answer, 'but you answered' 24 25 26 27 else: numCorrect += 1 index += 1 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 grade = int((numCorrect / 20) * 100) print (' The number of correctly answered questions: ', numCorrect) print (' The number of incorrectly answered questions: ' 20 - numCorrect) print (' Your grade is', grade, %') if grade <= 75: print (' You have not passed ') else: print (' Congrats you have passed ') except I0Error: print("The file could not be found") except IndexError: print ("There was an indexing error") except: print ("An error occurred") 4 45 46 47 main() 48 ON 00 O o
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education