Created
June 27, 2012 23:40
-
-
Save johnnyg/3007619 to your computer and use it in GitHub Desktop.
Calculates (interpolated) average grade
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
#!/usr/bin/env python2 | |
from itertools import izip, count | |
from math import fsum, ceil, floor | |
import fileinput | |
GRADES = ("FL", "PC", "PS", "CR", "DN", "HD") | |
MARKS = dict(izip(GRADES, count())) | |
def average(seq): | |
return fsum(seq)/len(seq) | |
def interpolated_grade(mark): | |
upper = int(ceil(mark)) | |
lower = int(floor(mark)) | |
grade = GRADES[lower] | |
if lower != upper: | |
grade += "/%s" % GRADES[upper] | |
return grade | |
mark = average([average([MARKS[grade] for grade in line.strip().split('/')]) for line in fileinput.input()]) | |
print "%s (%.1f)" % (interpolated_grade(mark), mark) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment