Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Last active August 29, 2015 13:58
Show Gist options
  • Save jasonkeene/10298115 to your computer and use it in GitHub Desktop.
Save jasonkeene/10298115 to your computer and use it in GitHub Desktop.
Script to calculate grade for CDA 3103 Spring 2014
#!/usr/bin/env python
# homework average is worth 15% of the grade and lowest will be thrown out
HOMEWORK = [
100, # hw1
100, # hw2
100, # hw3
100, # hw4
100, # hw5
]
# exams are worth 15% of the grade and one can be replaced by the final
EXAMS = [
100, # exam1
100, # exam2
]
# quiz is worth 15% of the grade and can not be replaced by the final
QUIZ = 100
# final is worth 40% of the grade
FINAL = 100
def calc_grade(homework, exams, quiz, final):
# drop lowest homework grade and calculate average
homework = sorted(homework)[1:]
homework_avg = float(sum(homework)) / len(homework)
# replace lowest exam with final if higher
exams = sorted(exams)
for i, score in enumerate(exams):
if final > score:
exams[i] = final
break
return sum([
homework_avg * 0.15,
exams[0] * 0.15,
exams[1] * 0.15,
quiz * 0.15,
final * 0.40,
])
if __name__ == '__main__':
print 'Your grade is:', calc_grade(HOMEWORK, EXAMS, QUIZ, FINAL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment