Instructions
This exam is individual, all answers must be your own work.
Save your answers to a directory
tests/quiz3
in yourcs2613
git repository. Commit and push tohttps://vcs.cs.unb.ca
before 10:20AM. If you havegit
problems, ask for help before the deadline.This exam is open book. You can use the course web site and your own git repo. Local copies of Practical Python, and the Python Documentation can be found at
The test file
medium.csv
will be available for download fromhttps://www.cs.unb.ca/~bremner/teaching/cs2613/tests/T3/
or you can type it in from the following
260, 60, 20, 60
20, 30, 20, 30
234, 54, 18, 54
195, 45, 15, 45
260, 0, 20, 0
0, 60, 0, 60
200, 40, 17, 33
Questions
In the following test file (called small.csv
below), the first row
represents category maximums, the second row represents category
weights, and the following rows represent student scores.
40, 20
25, 75
40, 10
20, 20
The first student (third row) has 40/40
in first category, but only
10/20
in the higher weighted second category, so their final score
is 62.5
. The second student (fourth row) has 20/40
in the first
category and 20/20
in the category worth 75%
, so their final score
is 87.5
. Your task it write a Python function averages
that
computes these weighted averages, and passes the following tests.
import pytest
def test_small():
assert averages("small.csv") == pytest.approx([62.5, 87.5], abs=0.02)
def test_medium():
assert averages("medium.csv") == \
pytest.approx([90.0, 75.0, 40.0, 60.0, 68.9], abs=0.02)
Passing
To get 6 marks (roughly a “C”), your solution must
- Pass the tests above.
- Use the builtin
csv
module to read the input files. - Have full test coverage.
Full marks
To get the full 10 marks, you must additionally
use only list comprehensions (no explicit loops, e.g.
for
orwhile
)use
zip
andsum