Lab: Doctests
Due: Wednesday, September 23 at 11:59pm (one week after it is assigned) · Worth: 4 points
Complete a game-night report: player groups, score comparisons, puzzle outcomes, and round results. The supplied rehearsal.py provides the event data and calls all 33 functions in lab.py. Write those functions yourself to practice choosing conditions, loops, and list operations. Their descriptions and doctests define the required behavior.
Start
Create lab-doctests from the starter template, clone your copy, and open it in VS Code. The first lab explains those steps. Open a terminal in the folder containing lab.py, check.py, and rehearsal.py, then run:
$ python3 rehearsal.pyThe blank starter reports 0 displayed, 33 unfinished, 0 errors. The rehearsal is ungraded practice; you do not need to edit either supplied runner. Use python on Windows if python3 is unavailable.
Check One Calculation
Read a function’s description and doctests, write its body, then check it:
$ python3 check.py is_evenReplace is_even with your function’s name. The runner shows each example and a pass/fail count without running the other unfinished functions. For a failure, compare Expected with Got and trace that input through your code. The Python reading covers return, conditions, loops, and collecting and ranking scores.
Build the Event Report
Work through the calculations in report order, rerunning rehearsal.py after each group:
| Report task | Functions to complete |
|---|---|
| Choose a date, pair players, and count playing orders | is_leap_year, is_even, is_odd, factorial |
| Compare scores and total awarded tokens | absolute_value, max_num, max_num_4, max_num_abs, median, sum_between |
| Evaluate the number-puzzle cards | num_digits, is_prime, is_perfect_square, fibonacci, near_ten, love6, funny_sum |
| Apply the squirrels’ party rules and the fictional birthday traffic law | cigar_party, speeding_fine |
| Find high and recent scores | largest, last_element, last_element_list, first_three, last_three, largest3, second_largest |
| Filter scores and check the position bonus | filter_odd, filter_even, bigger_than_10, has_index_at_value |
| Collect results across rounds | nested_filter_odd, flatten, filter_flatten |
Follow the docstrings for ties, boundaries, and empty or short lists. For example, max_num_abs returns an original input, which can be negative, and filter_odd removes odd values. filter_flatten selects the first item from the first list, the second from the second, and so on. The rehearsal gives each call fresh inputs so a function that sorts in place cannot reorder a later report line.
Check the Whole Report
A finished rehearsal displays 33 results with no unfinished rows or errors, but displayed values can still be wrong. Run all public doctests:
$ python3 -m doctest lab.pyNo output means they pass; add -v to see passing examples too. If Python cannot find the file, check that the terminal is in lab-doctests. Gradescope checks every function against the original doctests and additional inputs, including return types and unwanted printed output. Keep each function’s name and parameters, return the required value, and implement its general rule. Changing a doctest or the rehearsal data does not change the grading contract.
Submit
Commit and sync lab.py, then submit your lab-doctests repository and branch through Gradescope’s GitHub option. See the first lab for help. Keep the supplied runners for practice; their output is not a deliverable.
Grading Rubric
Gradescope checks each item separately and adds the points earned.
Total: 4 points.