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
dictwhere:
the key is the Student Id (
int)the value is a
listwith 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:>>> cl1 = [ ... [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_grades module (classroom_grades.py file):
- list_avg_by_row(classroomL, stgradesD)¶
such that
given
returns 2
list, one corresponding to rows in classroomL that are free of errors and one with the rows that are not:
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:
>>> sol = list_avg_by_row(cl1, stgD) >>> sol ([(1, 5.5, 4), (3, 7.5, 5)], [(2, 3, 25)])
Doctests are available at the list_avg_by_row.test file.
Note
To implement this function is recommended (but not mandatory) to call the following auxiliar function, hence it is recommended to first implement and test it:
- compute_avg(row, gradesD)¶
such that
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], ... } >>> cl1 = [ ... [22, -1, 42, 81, -1, 10, -1], ... [15, -1, 25, -1, -1, 36, 49], ... [92, -1, 72, -1, 31, 55, 99], ... ] >>> sol = compute_avg(cl1[0], stgD) >>> sol (True, 5.5, 4) >>> sol = compute_avg(cl1[1], stgD) >>> sol (False, 3, 25) >>> sol = compute_avg(cl1[2], stgD) >>> sol (True, 7.5, 5)
Doctests are available at the compute_avg.test file.