Lab: Doctests
Starter code: github.com/rtealwitter/lab-doctests
This is your first lab, and it doubles as your introduction to the workflow every later lab uses: complete a Python file until its doctests pass, push it to GitHub, and let an automated test run confirm your grade. The starter repository is 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.
None of the functions should take more than about five minutes, so the whole lab is a couple of hours of work. If you find yourself stuck on one for much longer than five minutes, that is a signal to ask for help (from me, a classmate, or a QCL tutor), not to grind.
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 are the easy problems, and the point of the easy problems is to build the fluency you will need for the later ones that an LLM cannot solve. If you cannot do these on your own now, you will not be able to do those later.
Getting the code
Fork the starter repository, github.com/rtealwitter/lab-doctests, to your own GitHub account with the Fork button. You now have your own copy that you are allowed to push to.
Clone your fork to your laptop and open the folder in VS Code:
$ git clone https://github.com/<your-username>/lab-doctests $ cd lab-doctests
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, write, run, read the failures, fix, until the command falls silent.
Submitting
Uploading to GitHub is always two steps, committing and then pushing:
$ git add lab.py
$ git commit -m 'complete lab.py'
$ git pushYour fork comes with a GitHub Actions workflow that runs the same doctests automatically every time you push. Enable Actions on your fork through its web interface, and after your next push you will see a tests badge turn from red to green once all doctests pass.
That green badge is the whole grading mechanism, and it is the loop you will repeat all term: the tests either pass or they do not, and you resubmit until they do. There is no partial credit, so keep going until every function is done and the badge is green. Then submit the URL of your fork on Gradescope.