1. Classroom Counting¶
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
dictwhere: the key is the Student Id (int) and the value is alistwith the name (str) and the grade (float) of that student. For example:>>> stgD = { ... 10: ['JBB', 0.0], ... 15: ['GWV', 5.5], ... 22: ['JJJ', 6.5], ... 27: ['AWV', 3.5], ... 31: ['MMP', 5.5], ... 35: ['BWV', 4.5], ... 42: ['SCC', 7.5], ... 49: ['BWV', 9.0], ... 55: ['FCC', 5.0], ... 72: ['ABC', 7.0], ... 81: ['GMM', 8.0], ... 92: ['MRP', 10.0], ... 99: ['ARG', 10.0], ... }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
listof rows. Each row in turn is alistofintwhich 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:>>> cl0 = [ ... [22, -1, 42, 81, -1, 10, -1], ... [15, -1, 25, -1, -1, 36, 49], ... [92, -1, 72, -1, 31, 55, 99], ... ]
Please implement the following Python function in the classroom module (classroom.py file):
- count_pass_fail(classroomL, gradesD)¶
such that
Note
Notice that a row might have no valid student ids at all. In this case both numbers should be 0.
For example, in case of the classroom above, the function should return the following:
>>> sol = count_pass_fail(cl0, stgD) >>> sol ([(1, 3, 1), (2, 2, 0), (3, 5, 0)], [25, 36])
Doctests are available at the count_pass_fail.test file.
Note
To implement this function is recommended to call an auxiliar function that traverses a single row and returns the number of pass, the number of fails and the list the erroneous student’s ids found.