Grades ====== Consider a list of students where each student is represented by a list with three components: - The student's name (:class:`srt`). - Whether the student is repeating course or not (:class:`bool`): If the value is ``True`` the student is repeating. - A sequence of the student grades (:class:`float` between 0.0 and 10.0). The number of grades is not fixed but it is always greater than 1. For example: .. literalinclude:: grade_classify.test :language: python3 :start-after: --stl-ini :end-before: --stl-fi 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 :mod:`grades` (file :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: .. py:function:: average(st) such that **given** *st* a :class:`list` with the information of a student as described above **returns** a :class:`float` with the average value of the student's grade discarding the worst one and rounded to 2 decimals. For example: .. literalinclude:: average.test :language: python3 :start-after: --ini :end-before: --fi Doctests are available in the :download:`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: .. py:function:: grade_classify(stL) such that **given** *stL* a :class:`list` of lists where each sublist is the information of an student as described above **returns** two new :class:`list` s: #. 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 :class:`list` of :class:`tuple` where each tuple contains the following student's information: - a :class:`str` with the student's name - a :class:`int` with the student's average grade rounded to 2 decimals. The input list should **not be modified**. For example: .. literalinclude:: grade_classify.test :language: python3 :start-after: --ini :end-before: --fi Doctests are available in the :download:`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: .. py:function:: grade_rank(stL) such that **given** *stL* a :class:`list` of lists where each sublist is the information of an student as described above **updates** *stL* by : #. Updating every student information by eliminating the information after the student's name and adding a :class:`float` with 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 :class:`int` at the beginning indicating the grade ranking of the student (starting at 1). For example: .. literalinclude:: grade_rank.test :language: python3 :start-after: --ini :end-before: --fi Doctests are available in the :download:`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: .. py:function:: grade_select(stL, mode) such that **given** - *stL* a :class:`list` of lists where each sublist is the information of an student as described above - *mode* a :class:`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: .. literalinclude:: grade_select.test :language: python3 :start-after: --ini :end-before: --fi Doctests are available in the :download:`grade_select.test` file.