UNB/ CS/ David Bremner/ teaching/ cs2613/ tests/ T3/ sample

Instructions

  1. This exam is individual, all answers must be your own work.

  2. Save your answers to a directory tests/quiz3 in your cs2613 git repository. Commit and push to https://vcs.cs.unb.ca before 10:20AM. If you have git problems, ask for help before the deadline.

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

    https://www.cs.unb.ca/~bremner/teaching/cs2613/books

  4. The test file medium.csv will be available for download from

    https://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

Full marks

To get the full 10 marks, you must additionally