Answer:
see explaination for program code
Step-by-step explanation:
Code below:
#!/usr/local/bin/python3
def main():
correct_ans = compareAnswers()
print('Correct answers are: %d' % correct_ans)
def compareAnswers():
# reads the content of file correct_answer.dat and student_answer.dat
correct_ans = open('correct_answer.dat')
stud_ans = open('student_answer.dat')
# adding correct answers to the list
c_ans = list()
for each_ans in correct_ans:
c_ans.append(each_ans)
# verifying how many answers are correct
i = 0
cnt_correct_ans = 0
for each_ans in stud_ans:
if each_ans == c_ans[i]:
cnt_correct_ans += 1
i += 1
return cnt_correct_ans
if __name__=='__main__':
main()
Go to attachment for screenshot of source code and output