Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Put ALL your code for this question in a single module \"grading.py\" An exam ha

ID: 3570875 • Letter: P

Question

Put ALL your code for this question in a single module "grading.py"

An exam has 20 multiple-choice questions (A,B,C,D). A student answer is stored in a
file with each line containing a letter. The correct answers are defined by this list:

solution =    ['A', 'C', 'A', 'A', 'D',
'B', 'C', 'A', 'C', 'B',
'A', 'D', 'C', 'A', 'D',
'C', 'B', 'B', 'D', 'A']
              
Student passes the exam if 15 or more answers are correct.
Print out the message
              
Write the code to ask user to enter a file name containing the student answers.
The code prints "Congratulations!! You passed the exam." or
"Sorry, you did not pass the exam."

Print the number of correct answers, incorrect answers, and the list of incorrect answers.

Your are given 3 test files to test your code individually:
-answer1_20.txt
-answer2_18.txt
-answer3_12.txt

If user enter a file that does not exist, print an error messag?

>>>
Enter student answer file: answer1_20.txt
Congratulations!! You passed the exam.
Number of questions you answered correctly: 20
Number of questions you answered incorrectly: 0
>>> ================================ RESTART ================================
>>>
Enter student answer file: answer2_18.txt
Congratulations!! You passed the exam.
Number of questions you answered correctly: 18
Number of questions you answered incorrectly: 2
Questions you answered incorrectly:14, 18
>>> ================================ RESTART ================================
>>>
Enter student answer file: answer3_12
The file could not be found
>>> ================================ RESTART ================================
>>>
Enter student answer file: answer3_12.txt
Sorry, you did not pass the exam.
Number of questions you answered correctly: 12
Number of questions you answered incorrectly: 8
Questions you answered incorrectly:1, 2, 6, 7, 9, 14, 18, 20

Answers to enter

Answer 1 _20 : A,C,A,A,D,B,C,A,C,B,A,D,C,A,D,C,B,B,D,A

Answer 2_18 : A,C,A,A,D,B,C,A,C,B,A,D,C,B,D,C,B,C,D,A

Answer 3_12 : D,B,A,A,D,A,B,A,D,B,A,D,C,B,D,C,B,C,D,B

Explanation / Answer

#!/usr/bin/python

file=raw_input("Enter student answer file: ");
fo = open(file , "r");
ans = fo.read(40);
solution = ['A', 'C', 'A', 'A', 'D','B', 'C', 'A', 'C', 'B','A', 'D', 'C', 'A', 'D','C', 'B', 'B', 'D', 'A']
correct=0
it=0
j=0
k=0
for sol in solution:
   if (sol == ans[j]): correct=correct+1
   else:
       lis[k]=sol
       k=k+1
   j=j+2
if (correct>14):
   print ('Congratulations. You passed the exam.')
else:
   print ('Sorry, you did not pass the exam.')
print ('Number of questions you answered correctly: ',correct)
print ('Number of questions you answered incorrectly: ',(20-correct))
if(correct<20):
   print ("Questions you answered incorrectly: ",lis[0:])

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote