d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Can Someone Write A Program For Me? > 500 Fg
Prev123Next
Add Reply New Topic New Poll
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 19 2016 10:26pm
Quote (Azrad @ Feb 19 2016 03:02pm)
could do this in python in a couple mins, sans the whole platform/input issue. How exactly are you receiving the answers to be graded? I don't know much about chromebooks, but I saw an addon for them (chrome) that lets you run python, but not sure how it works.


Recieving the answers in .txt form
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 20 2016 03:57am
Quick and dirty proof of concept.

grade.py:
Code
import glob, os, re


def load_file(filename, re_pattern):
student_dict = {}
with open(filename) as grade_file:
raw_data = grade_file.read().split('\n\n')
for i, raw_section in enumerate(raw_data):
if re_pattern.findall(raw_section):
student_dict['section' + str(i+1)]=re_pattern.findall(raw_section)
return student_dict


def get_student_list(path, keyfile_name):
student_list = glob.glob('./*.txt')
return [student for student in student_list if student != keyfile_name]


def grade_test(student_name, answer_key, re_pattern):
total_earned_points = total_possible_points = 0
student_answers = load_file(student_name, re_pattern)
print os.path.basename(student_name).split('.')[0], '\n'
for section_name in answer_key:
section_analysis, num_correct_answers = [], 0
for i, answer in enumerate(answer_key[section_name]):
if answer == student_answers[section_name][i]:
num_correct_answers += 1
else:
section_analysis.append(('#%d: You marked: %s. Correct Answer: %s') % \
(i+1, student_answers[section_name][i], answer))
total_earned_points += num_correct_answers
total_possible_points += i + 1
print section_name + ':'
print 'Score', num_correct_answers, '/', i + 1
print 'Percentage:', num_correct_answers * 100.0 / (i+1), '%'
for entry in section_analysis:
print entry
print ''
print "Overall\nNumber of Sections:", len(answer_key),
print 'Total Score:', total_earned_points, '/', total_possible_points
print '---------------------------------'


keyfile_name = './Key.txt'
re_pattern = re.compile(r'\d. (\w)')
answer_key = load_file(keyfile_name, re_pattern)
student_list = get_student_list('./*.txt', keyfile_name)
print '---------------------------------'
for student in student_list:
grade_test(student, answer_key, re_pattern)



Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 20 2016 03:58am
Some sample output:
Code
Sam

section3:
Score 1 / 2
Percentage: 50.0 %
#1: You marked: B. Correct Answer: A

section2:
Score 0 / 4
Percentage: 0.0 %
#1: You marked: C. Correct Answer: E
#2: You marked: C. Correct Answer: E
#3: You marked: C. Correct Answer: E
#4: You marked: C. Correct Answer: E

section1:
Score 13 / 13
Percentage: 100.0 %

Overall
Number of Sections: 3 Total Score: 14 / 19
---------------------------------
Joe

section3:
Score 0 / 2
Percentage: 0.0 %
#1: You marked: F. Correct Answer: A
#2: You marked: F. Correct Answer: B

section2:
Score 4 / 4
Percentage: 100.0 %

section1:
Score 13 / 13
Percentage: 100.0 %

Overall
Number of Sections: 3 Total Score: 17 / 19
---------------------------------
Bob

section3:
Score 1 / 2
Percentage: 50.0 %
#2: You marked: A. Correct Answer: B

section2:
Score 0 / 4
Percentage: 0.0 %
#1: You marked: D. Correct Answer: E
#2: You marked: D. Correct Answer: E
#3: You marked: D. Correct Answer: E
#4: You marked: D. Correct Answer: E

section1:
Score 13 / 13
Percentage: 100.0 %

Overall
Number of Sections: 3 Total Score: 14 / 19
---------------------------------


It expects a studentname.txt file for each student, the key to be named: Key.txt, and for these files to be in the same directory that contains nothing else.
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 20 2016 08:56am
https://repl.it/languages/python3 or http://www.skulpt.org/ - how do I upload the .txt files?
Feb 20 2016 09:40am
Inappropriate Post Content
Feb 22 2016 12:00am
Inappropriate Post Content
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 22 2016 12:50am
Sure but it will involve a rewrite of most of the functions, then you will just want another change, forcing another rewrite, etc, etc. Why don't you post an EXACT example of a keyfile, student file, and what you want the report to look like.

Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 22 2016 11:18am
Quote (Azrad @ Feb 21 2016 11:50pm)
Sure but it will involve a rewrite of most of the functions, then you will just want another change, forcing another rewrite, etc, etc. Why don't you post an EXACT example of a keyfile, student file, and what you want the report to look like.



Keyfile:
ABBCCc dddD EEeeE // (caps/uncaps doesn't change anything)

Studentfile:

Section 1
a
b
b
c
c
c
c

Section English
e
e
e
d

Section Math
e
e
e
e
e
e

Output:

Same as before. Except the section name should correspond to the label in the studentfile.
Member
Posts: 31,577
Joined: Apr 5 2007
Gold: 1.00
Mar 4 2016 12:50am
You should create a program,

that formulates
variable questions as input

create if statement to answers//return correct or wrong variable
do a count method of wrong or right
calculate percentage as answers/questions


Member
Posts: 17,487
Joined: Jan 24 2006
Gold: 22,454.47
Mar 4 2016 03:01am
could do this in c++ for you

some questions:
1) i guess the output should be in a .txt data,? so youll be able to copy the answeres to a word data or something like that.
2) the correct answeres should be written in a .txt as well? or do you want to enter them in the program?
3) you want a real gui, or its okay to write is simple as fuck down for a shell?

i would program it generic, so you could use it for any multiple choice tests.
Go Back To Programming & Development Topic List
Prev123Next
Add Reply New Topic New Poll