Last active
October 23, 2016 21:30
-
-
Save s2t2/970e0eadad01d6307f6a2fbf55aab1ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# | |
# PARSE STUDENT ANSWERS FROM FILE | |
# | |
# choose the right file (must be in the same directory as this script!) | |
filename = os.path.join(os.path.dirname(__file__), 'student_answers.csv') | |
print(filename) | |
# read the file contents into memory | |
infile = open(filename, 'r') | |
student_answers = infile.readlines() | |
infile.close() | |
# clean the list by stripping line-breaks | |
index = 0 | |
while index < len(student_answers): | |
student_answers[index] = student_answers[index].rstrip('\n') | |
index += 1 | |
print(student_answers) | |
# | |
# COMPARE STUDENT ANSWERS WITH CORRECT ANSWERS | |
# | |
answer_key = [ | |
"A","C","A","A","D", | |
"B","C","A","C","B", | |
"A","C","D","A","D", | |
"C","B","B","D","A" | |
] | |
correct_answers = [] | |
incorrect_answers = [] | |
for index, student_answer in enumerate(student_answers): | |
correct_answer = answer_key[index] # we assume the student answer file is in the same order as the answer key | |
student_answer_is_correct = (student_answer == correct_answer) | |
question_number = index + 1 | |
if (student_answer_is_correct): | |
correct_answers.append(question_number) | |
else: | |
incorrect_answers.append(question_number) | |
print("ON QUESTION NUMBER " + str(question_number) + ", STUDENT CHOSE: " + student_answer + " AND CORRECT ANSWER IS: " + correct_answer + ". STUDENT IS CORRECT?: " + str(student_answer_is_correct)) | |
# | |
# DISPLAY RESULTS | |
# | |
print("STUDENT CHOSE " + str( len(correct_answers) ) + " CORRECT ANSWERS: " + str(correct_answers)) | |
print("STUDENT CHOSE " + str( len(incorrect_answers) ) + " INCORRECT ANSWERS: " + str(incorrect_answers)) | |
student_passed = (len(correct_answers) >= 15) | |
print("STUDENT PASSED?: " + str(student_passed)) |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A | |
A |
Author
s2t2
commented
Oct 23, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment