Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- marks = [75, 45, 89, 55, 65, 50, 72, 70, 60, 80, 95, 34, 83, 71, 65, 53, 58, 79, 85, 21, 67, 94, 77]
- def grade_single_score(score_mark):
- grades = [['U', 0, 49], ['D', 50, 59], ['C', 60, 69], ['B', 70, 79], ['A', 80, 89], ['A*', 90, 100]]
- for grade in grades:
- if grade[1] <= score_mark <= grade[2]:
- return grade[0]
- return 'N/A'
- def grade_and_print_scores(score_list):
- for idx, score in enumerate(score_list): print("Mark [%d] - %d - %s" % (idx, score, grade_single_score(score)))
- def print_grade_distribution(score_list, grades_distr = {}):
- for score in score_list:
- grade = grade_single_score(score)
- grades_distr[grade] = 1 if not grades_distr.has_key(grade) else grades_distr[grade] + 1
- for grade, frequency in sorted(grades_distr.items(), lambda lhs, rhs: -1 if lhs[0].endswith('*') else cmp(lhs, rhs)):
- print("Grade %s - %i" % (grade, frequency))
- grade_and_print_scores(marks)
- print("--------------------")
- print_grade_distribution(marks)
Add Comment
Please, Sign In to add comment