Grades¶
Consider a list of students where each student is represented by a list with three components:
For example:
>>> stL = [ ... ['Aina', False, 2.5, 5.9, 4.8, 5.3], ... ['Marc', False, 3.0, 9.6, 5.3, 4.7, 5.9], ... ['Roc', True, 4.5, 7.0, 5.7, 3.2, 4.5, 8.8], ... ['Ona', True, 0.0, 3.3, 5.2, 7.5] ... ]
The average grade of a student is defined as the average of all his/her grades but the worst one (ie. the worst grade is discared before computing the average).
You are required to implement the following functions related to a list of students and deliver all of them in the same module grades (file grades.py).
The weights of these functions are 10%, 40%, 40% and 10% respectively.
Since the two main functions requested do require the computation of the average as described, first let’s proceed by implementing the following auxiliary fuction:
- average(st)¶
such that
For example:
>>> average(['Felip', True, 7.0, 1.7, 3.2, 4.5, 3.8]) 4.62 >>> average(['Joan', False, 2.9, 4.8, 8.3]) 6.55
Doctests are available in the average.test file.
Now, we first wish to separate the students between those who passed and those who did not. To that purpose you have to implement the following function:
- grade_classify(stL)¶
such that
given stL a
listof lists where each sublist is the information of an student as described abovereturns two new
lists:
the list of the students who passed (the average grade is >= 5.0) in alphabetical order by the student’s name.
the list of the students who did not pass also in alphabetical order.
Both are
listoftuplewhere each tuple contains the following student’s information:The input list should not be modified.
For example:
>>> stL = [ ... ['Joan', False, 2.9, 4.8, 8.3], ... ['Mario', True, 4.5, 5.5, 6.5, 7.5], ... ['Maria', False, 9.6, 9.3, 4.7, 9.9], ... ['Felip', True, 7.0, 1.7, 3.2, 4.5, 3.8], ... ['Mar', True, 5.3, 6.5] ... ] >>> stLcopy = stL.copy() >>> grade_classify(stL) ([('Joan', 6.55), ('Mar', 6.5), ('Maria', 9.6), ('Mario', 6.5)], [('Felip', 4.62)])
Doctests are available in the grade_classify.test file.
Second, we wish to rank the students from high to low average grade. To that purpose you have to implement the following function:
- grade_rank(stL)¶
such that
given stL a
listof lists where each sublist is the information of an student as described aboveupdates stL by :
Updating every student information by eliminating the information after the student’s name and adding a
floatwith the student’s grades average rounded to 2 decimals before the name.Ordering the students list from high to low average grade.
Adding to every student an
intat the beginning indicating the grade ranking of the student (starting at 1).
For example:
>>> l = [ ['Joan', False, 2.9, 4.8, 8.3], ... ['Mario', True, 4.5, 5.5, 6.5, 7.5], ... ['Maria', False, 9.6, 9.3, 4.7, 9.9], ... ['Felip', True, 7.0, 1.7, 3.2, 4.5, 3.8], ... ['Mar', True, 5.3, 6.5] ... ] >>> sol = [[1, 9.6, 'Maria'], [2, 6.55, 'Joan'], [3, 6.5, 'Mario'], [4, 6.5, 'Mar'], [5, 4.62, 'Felip']]
Doctests are available in the grade_rank.test file.
Third, we wish to select either the students that are repeating or the ones that are new. To that purpose you have to implement the following function:
- grade_select(stL, mode)¶
such that
For example:
>>> stL = [ ['Felip', True, 7.0, 1.7, 3.2, 4.5, 3.8], ... ['Joan', False, 2.9, 4.8, 8.3], ... ['Maria', False, 9.6, 9.3, 4.7, 9.9], ... ['Mar', True, 5.3], ... ['Robert', False, 5.0, 2.5, 7.5, 4.0] ] >>> grade_select(stL, 'new') >>> stL == [['Joan', False, 2.9, 4.8, 8.3], ['Maria', False, 9.6, 9.3, 4.7, 9.9], ['Robert', False, 5.0, 2.5, 7.5, 4.0]] True
Doctests are available in the grade_select.test file.