-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSC500_Grade_a_Student_Exam
51 lines (46 loc) · 2.1 KB
/
CSC500_Grade_a_Student_Exam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This program grades an exam by comparing the answers in a student’s text file to the items in a list containing the answer key.
# I made two text files to test it with: one control file that matches the answer key 100%, and one that I generated by repeating the same arbitrary combination of ABCD until I had 20 letters.
# Testing with the control file illuminated a need to remove any characters that didn’t correspond to a test answer before grading—which might not be necessary in a real-world grading scenario,
# but I followed “better safe than sorry” reasoning.
# The program assumes that each of the 20 questions is worth five points. It outputs “+5 points” for each correct answer and “0 points” for each incorrect answer,
# then prints both the final grade and a message that tells the student whether they passed the exam.
#Creates a list containing the answer key
answer_key = list('ACAADBCACBADCADCBBDA')
#Reads the student's answers from a text file into a list
student_file = open(input('Hello! What file would you like to grade? '), 'r')
answers = list(student_file.read())
#We only want to grade answers, so we're going to strip out any extra characters (such as \n or numbering) that might have been in the student's answer file.
for i in range (0,50):
if '\n' in answers:
answers.remove('\n')
if int in answers:
answers.remove(int)
if '.' in answers:
answers.remove('.')
#Setting initial values of i and grade variables to 0
i = 0
grade = 0
print()
for i in range(0,20):
if answers[i] == answer_key[i]: #compares items in answers to items in answer_key
grade += 5 #assumes 5 points per question for a total of 100
print('Question', i + 1, end = ": ")
print('+ 5 points')
print()
else:
grade += 0
print('Question', i + 1, end = ": ")
print('0 points')
print()
else:
print()
print()
print('Your final grade is', grade, end = '/100')
print()
print()
print()
#Prints either a pass or fail message
if grade < 75: #15*5
print('Sorry—That\'s NOT a passing grade.')
else:
print('Congratulations! You PASSED the exam.')