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):
- grade = grade_single_score(score)
- print("Mark [%d] - %d - %s" % (idx, score, grade))
- def compare_tuple_by_grade(lhs, rhs):
- if lhs[0].endswith('*'):
- return -1
- return cmp(lhs, rhs)
- def print_grade_distribution(score_list):
- grades_distr = {}
- for score in score_list:
- grade = grade_single_score(score)
- if not grades_distr.has_key(grade):
- grades_distr[grade] = 1
- else:
- grades_distr[grade] = grades_distr[grade] + 1
- for grade, frequency in sorted(grades_distr.items(), compare_tuple_by_grade):
- print("Grade [%s] - %i" % (grade, frequency))
- grade_and_print_scores(marks)
- print("--------------------")
- print_grade_distribution(marks)
Add Comment
Please, Sign In to add comment