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 dict where: the key is the Student Id (int) and the value is a list with 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 list of rows. Each row in turn is a list of 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:

    
    >>> 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

given

  • classroomL, a classroom list as described above.

  • gradesD, a grades dict as described above.

  • It is not garanteed that all Student Id in the classroom appear as a key in gradesD and such a situation is considered an error.

returns 2 list:

  • A list such that for each row in classroomL, there is a 3-values tuple:

    1. The row number (int): Bear in mind that the initial row index is 1.

    2. The number of students (int >= 0) in that row that passed (ie. grade >= 5.0).

    3. The number of students (int >= 0) in that row that failed.

  • A list of all the erroneous student ids found in the classroom. This list must contain repetitions.

Both lists must be increasingly ordered.

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.