Lab: Doctests
Due: Wednesday, September 23 at 11:59pm (one week after it is assigned) · Worth: 4 points
A Python function takes inputs and can return a result. You’ll write 16 functions and use the examples in their descriptions to check how each one behaves.
Start
Download and extract the starter ZIP. Open the inner lab-doctests folder in VS Code, then initialize and publish your repository as lab-doctests. Open lab.py. The supplied check.py can run one function’s examples while the others remain unfinished.
Complete the functions
Start with one function in lab.py. Its docstring describes the result and gives examples. Fill in the function body, then run its examples before moving on to the next function. The Python reading covers conditions, calculations, and lists.
For example, python check.py is_even runs just the examples for is_even. If one fails, compare the expected result with the one your function returned. Check the docstring for cases such as ties or empty lists.
Conditions
-
Implement
is_even,absolute_value,max_num,median,is_leap_year. Each function is worth 0.25 points.
Loops
-
Implement
factorial,sum_between,num_digits,is_prime. Each function is worth 0.25 points.
Lists
-
Implement
last_element,first_three,largest3. Each function is worth 0.25 points.
Loops over lists
-
Implement
filter_odd,bigger_than_10,has_index_at_value,flatten. Each function is worth 0.25 points.
Check and submit
Run all the examples from the repository folder:
python -m doctest lab.pyIf the command finishes without printing anything, the examples passed. Gradescope also checks the same functions with other inputs.
Commit and sync lab.py. On Gradescope, choose GitHub and submit lab-doctests and the branch containing your work. The submission guide explains resubmission.