Classroom Grades ================ Let's consider the hypothetical scenario of a group of students who have taken a programming exam. The professor responsible of that exam is interested in knowing the average grade of the grades of the students seating in the same row. The information available is the following: - A **grades dictionary**: A :class:`dict` where: - the key is the *Student Id* (:class:`int`) - the value is a :class:`list` with the name (:class:`str`) and the grade (:class:`float`) of that student. For example: .. literalinclude:: list_avg_by_row.test :language: pycon :start-after: --ini-D :end-before: --fi-D - A **classroom list**: This is a 2-dimension list representing the locations where the students were seating during the exam. More precisely it is a :class:`list` of **rows**. Each row in turn is a :class:`list` of :class:`int` which is either a *Student Id* or -1 is nobody was seating in that place. Rows are counted top-down starting at 1 and locations are counted from left to right starting at 1. For example: .. literalinclude:: list_avg_by_row.test :language: pycon :start-after: --ini-cl1 :end-before: --fi-cl1 Please implement the following Python function in the :mod:`classroom_grades` module (:file:`classroom_grades.py` file): .. py:function:: list_avg_by_row(classroomL, stgradesD) such that **given** - ``classroomL``, a classroom :class:`list` as described above. - ``stgradesD``, a grades :class:`dict` as described above. - It is **not garanteed** that all *Student Id* in the classroom appear as a key in ``gradesD``. This is considered an error. **returns** 2 :class:`list`, one corresponding to rows in *classroomL* that are free of errors and one with the rows that are not: #. "OK list": For each row in *classroomL* that has no errors, there is a :class:`tuple` with 3 values: - The row number (:class:`int`): Remember that the row indexes starts a 1. - The average grade (:class:`float`) of the grades of the students in that row rounded to 1 decimal. - The number of students in that row (ie. the ones used to computer the average grade). #. "Not OK list": For each row in *classroomL* that that has one or more errors there is :class:`tuple`) with 3 :class:`int` values: - The row number (:class:`int`): Remember that the row indexes starts a 1. - The seat number (:class:`int`) of the first "error" found (considering the ordering of seat indicated in the classroom list description). - The erroneous student's id (:class:`int`). .. note:: Notice that a row might have no students at all. In this case the average grade would be -1.0. For example, in case of the classroom above, the function should return the following: .. literalinclude:: list_avg_by_row.test :language: pycon :start-after: --ini-out :end-before: --fi-out Doctests are available at the :download:`list_avg_by_row.test ` file. .. note:: To implement this function is recommended (but not mandatory) to call the following auxiliar function. Therefore it is recommended to first implement and test this function: .. py:function:: compute_avg(row, gradesD) such that **given** - ``row`` a :class:`list` of :class:`int` representing a row as described above. - ``gradesD``, a :class:`dict` of students grades as described above. **returns** a tuple with3-value tuple that is different depending on whether the row is OK all student's ids occur as a key in *gradesD*) or is not. - It the row is OK it returns a 3-component :class:`tuple` with: #. ``True`` #. The **average grade** of the grades of the students in that row (:class:`float` rounded to 1 decimal). #. The **number of students** (:class:`int`) in that row (ie. the ones used to computer the average grade). - It the row is not OK, it returns: #. ``False`` #. The seat number (:class:`int`) of the first "error" found. #. The erroneous student's id (:class:`int`). For example: .. literalinclude:: compute_avg.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available at the :download:`compute_avg.test ` file.