Grades

Consider a list of students where each student is represented by a list with three components:

  • The student’s name (srt).

  • Whether the student is repeating course or not (bool): If the value is True the student is repeating.

  • A sequence of the student grades (float between 0.0 and 10.0). The number of grades is not fixed but it is always greater than 1.

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

given st a list with the information of a student as described above

returns a float with the average value of the student’s grade discarding the worst one and rounded to 2 decimals.

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 list of lists where each sublist is the information of an student as described above

returns two new list s:

  1. the list of the students who passed (the average grade is >= 5.0) in alphabetical order by the student’s name.

  2. the list of the students who did not pass also in alphabetical order.

Both are list of tuple where each tuple contains the following student’s information:

  • a str with the student’s name

  • a int with the student’s average grade rounded to 2 decimals.

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 list of lists where each sublist is the information of an student as described above

updates stL by :

  1. Updating every student information by eliminating the information after the student’s name and adding a float with the student’s grades average rounded to 2 decimals before the name.

  2. Ordering the students list from high to low average grade.

  3. Adding to every student an int at 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

given

  • stL a list of lists where each sublist is the information of an student as described above

  • mode a str

updates stL by leaving only the students that are new if mode is 'new', or the ones that are repeating if mode is 'rep'. If mode is anything else the list stL must remain unchanged.

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.