HW5: Knitout Writer Class
Assigned: 4/14/2026
Code Due: 4/23/2026 at 11:59 PM (Submit on Gradescope)
Feedback Returned By: 4/26/2026
Overview
In this assignment, you will implement a KnitoutWriter class that generates knitout files, the file format used to control our Shima Seiki knitting machine. In previous assignments, knitout instructions were generated by standalone functions in knitout_helpers.py. Now you will wrap that functionality into a well-designed class that manages carriers, validates operations, and produces correctly formatted output.
A set of tests is provided in test_knitout_writer.py to guide your implementation and help you debug. If you would like to practice more on Python programming, you can look for the Exercise sections at the end of corresponding chapters of the textbook Think Python 3e.
Competencies and Evidence Points
HW5 maps to 1 Evidence Point under the Data Structures & Algorithms competency, and 1 Evidence Point under the Software Engineering Practices competency, and 2 Evidence Points under the Object-Oriented Programming & Design competency.
Object-Oriented Programming & Design (2 Evidence Points)
EP1 — Class Definition and Conceptual Understanding
Satisfactory work shows you can:
- Define a class with
__init__and multiple methods - Use
selfcorrectly to access and modify instance attributes - Understand the differences between class variables and instance attributes and when to use them
EP2 — State Management and Testing OOP
Satisfactory work shows you can:
- Implement input validation and invariant checks using
assertor exceptions - Manage object state (active carriers, instruction list, racking)
Data Structures & Algorithms (1 Evidence Point)
EP3 — Lists, Sets, and String Formatting
Satisfactory work shows you can:
- Use lists to accumulate instructions in order
- Use sets to track active carriers
- Use format strings to format output correctly
- Combine data structures to produce structured text output
Software Engineering Practices (1 Evidence Point)
EP4 — Code Quality and Testing
Satisfactory work shows you can:
- Write code that passes all provided tests and provide meaning error messages in
assert - Reduce code repetition using private helper methods
- Maintain readable code: consistent style (snake_case), clear names, appropriate docstrings
- Required citations of at least two sources
Preparation Before You Start
Download comp116-hw5.zip from Ed Discussion > Resources.
This assignment will be completed in two files: (1) warm-up exercises by editing a Jupyter Notebook file comp116-hw5.ipynb; (2) the KnitoutWriter class by editing a Python file knitout_writer.py. A test file test_knitout_writer.py is provided; do not modify this file.
A reminder to create a separate folder for hw5 to keep under the course homeworks/assignments folder. You can unzip the comp116-hw5.zip into the hw5 subfolder.
You can now use VSCode to open the folder that contains the files of this assignment.
For working on the Jupyter notebook: navigate to open the Jupyter notebook file for this assignment. Don’t forget to select the comp116 kernel in the top right corner of the window before running the code cells in the notebook!
For working on the Python file: navigate to open knitout_writer.py and implement each method marked with # TODO. To run the tests, open a terminal, activate the comp116 environment, and run:
python test_knitout_writer.py
The tests are organized into parts (Constructor, Carriers, Operations, Output, Integration). We recommend implementing and testing one part at a time; see more details in the notebook.
How to Submit
Go to Moodle and find the Gradescope link for “HW5: Knitout Writer Class” and upload your completed comp116-hw5.ipynb (keeping all the cell outputs instead of clearing them), the .k file you used for Exercise 1.1, knitout_writer.py, and the generated “stockinette_swatch.k” to Gradescope.
Questions? Post on Ed Discussion or come to office hours!