Lab: Doctests
Due: Wednesday, September 23 at 11:59pm (one week after it is assigned) Worth: 4 points
Starter repository: github.com/rtealwitter/lab-doctests
This lab introduces the workflow used in later labs: complete a Python file until its doctests pass, push it to GitHub for preliminary feedback, and submit the repository on Gradescope for the authoritative test result. The starter repository contains lab.py, a file of about thirty short functions whose bodies are blank. Each one has a description and a set of doctests; your job is to write the body so that every doctest passes.
Each function should take about five minutes, for a total of roughly two hours. If you spend much longer than five minutes on one function, ask me, a classmate, or a QCL tutor for help.
A warning before you start. Every function in this lab can be solved instantly by an LLM like ChatGPT or Copilot. Write them yourself anyway. These problems build the fluency you will need for later work that an LLM cannot solve. If you cannot do these on your own now, you will not be able to do those later.
Start
On the starter repository, select Use this template to create an independent lab-doctests repository under your account. Clone that repository and open it in VS Code.
The Loop
Open lab.py and work one function at a time. For each function, read its description and doctests, write the body, then run the doctests from your terminal:
$ python3 -m doctest lab.pySilence means every test passed. While tests are still failing, the command prints each failing example with what it Expected and what it Got, so you always know exactly which function to fix next. Add -v if you want to see the passing tests tallied up too. Repeat this process until the command falls silent. Gradescope runs an instructor-owned copy of the starter’s examples, so deleting or changing a doctest does not change what is required. Its feedback identifies the function, the input, the expected result, and what your function returned or printed.
Submit
Before submitting:
Commit and sync lab.py, then on Gradescope choose GitHub and submit your lab-doctests repository and the branch containing your commit.