Skip to content

Instantly share code, notes, and snippets.

@rkrishnasanka
Last active August 29, 2015 14:06
Show Gist options
  • Save rkrishnasanka/f5575824d2ea549df294 to your computer and use it in GitHub Desktop.
Save rkrishnasanka/f5575824d2ea549df294 to your computer and use it in GitHub Desktop.
Prints out corrects , partials and wrongs from the detail string
Groupa 0 ++ / 1+ 2a++ b++ c+++-/- d-- 3a- b-
Groupb 0++- 1+ 2a+/ b++ c+++--- d-- 3a- b-
Group4 0++/ 1+ 2a++ b++ c+++--- d-- 3a- b-
Group5 0++- 1+ 2a+/ b-- c------ d-- 3a- b-
Group6 0+++ 1? 2a++ b++ c-+/-// d-- 3a+ b-
Group7 0++- 1+ 2a// b// c-/---- d-- 3a- b-
Group8 0++/ 1+ 2a// b++ c+++-/- d// 3a- b-
Group9 0++- 1+ 2a-/ b// c-+---- d++ 3a- b-
Group1 0+++ 1+ 2a-/ b// c-+--/- d-- 3a- b-
def parseDetail(line):
corrects = 0
wrongs = 0
partials = 0
for i in range(0,len(line)):
c = line[i]
if c=='+': corrects=corrects+1
if c=='-': wrongs=wrongs+1
if c=='/': partials=partials+1
return corrects, wrongs ,partials
def trim(line):
if line[0] == ' ':
if line[len(line)-1] == ' ':
return line[1:len(line)-2]
else:
return line[1:]
if line[1:len(line)-1] == ' ':
return line[:len(line)-2]
return line
ifile = open("details.txt" , "r")
ofile = open("results.txt" , "w")
for line in ifile:
if line == '\n': continue
c,w,p = parseDetail(line)
output = "| "+str(c) + " | " + str(p) + " | " + str(w) + " | =" + trim(line) +"= |"+"\n"
ofile.write(output)
print output
ifile.close()
ofile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment