HW3: Basic Colorwork

Assigned: 2/24/2026
Code Due: 3/5/2026 at 11:59 PM (Submit on Gradescope)
Feedback Returned By: 3/24/2026 (after spring break)

Fabrication: 3/5/2026 during lecture or sign up for open hours (check Ed posts from TAs) Fabrication Artifact Due: 4/14/2026

Overview

In this assignment, you will first work through some warm-up exercises on strings, file I/O, and nested lists, and then implement a pattern generator that can take in an image input and generate a three-color knitting pattern. 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

HW3 maps to 1 Evidence Point under the Programming Fundamentals competency, 1 Evidence Point under the Data Structures & Algorithms competency, 1 Evidence Point under the Software Engineering Practices competency, and 1 Evidence Point under the Fabrication & Physical Computing competency.

Programming Fundamentals (1 Evidence Points)

EP1 — Strings and File IO
Satisfactory work shows you can:

  • Apply string methods combined with conditionals to transform and process text
  • Open files to read and write
  • Understand strings enough to come up with meaningful edge cases for testing

Data Structures & Algorithms (1 Evidence Points)

EP2 — Nested Lists
Satisfactory work shows you can:

  • Use loops to iterate over and search within nested lists
  • Create, populate, and modify nested lists with appropriate values
  • Use nested lists to represent and manipulate images

Software Engineering Practices (1 Evidence Point)

EP3 — Code Quality and Testing (overall quality)
Satisfactory work shows you can:

  • Find multiple, meaningfully different test cases, including edge cases, to probe the effect on the output
  • Maintain readable code: consistent style (snake_case), clear names, appropriate amount of comments and docstrings (explain not obvious parts and not too extensive)
  • Required citations of at least two sources

Fabrication & Physical Computing (1 Evidence Point)

EP4 - Knitting the Artifact
Satisfactory work shows you can:

  • Connect abstract code to physical knitted output
  • Generate valid machine code from your pattern generator
  • Operate the knitting machine independently to fabricate a custom pattern
  • Troubleshoot fabrication errors and iterate if needed
  • Document your physical artifact with photo and observations

Preparation Before You Start

Download comp116-hw3.zip from Ed Discussion > Resources.

This assignment will be completed in two files: (1) the warm-up exercises by editing a Jupyter Notebook file comp116-hw3.ipynb; (2) the pattern generator by editing a Python file pattern_generator.py.

A reminder to create a separate folder for hw3 to keep under the course homeworks/assignments folder. You can unzip the comp116-hw3.zip into the hw3 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 the Python file and edit that file. To run the file, please follow the steps from the Ed post on How to Run a Python File.

How to Submit

Code Submission

Go to Moodle and find the Gradescope link for “HW3: Basic Colorwork” and upload your completed comp116-hw3.ipynb (keeping all the cell outputs instead of clearing them) and pattern_generator.py to Gradescope. You can also upload the generated knitout files (*.k) you tried for testing.

Fabrication Artifact Submission

Go to Moodle and find the Gradescope link for “HW3: Basic Colorwork - Fabrication Artifact” and upload the following:

  1. Photo of your knitted artifact
    • Clear, well-lit photo showing the full pattern
    • Include a ruler or size reference if specified
  2. Brief description (2-3 sentences)
    • Describe the image and the threshold values you used
    • Any observations about the physical result vs. your expectations
    • Any challenges encountered during fabrication

Example Artifacts

What you can expect from this assignment is as follows:

Input Front Back
Example, t100,150, c1,2,3
Cardinal, t40,150, c2,3,1

Note that we do not expect the artifact to be free of errors; the machine is not tuned to perfection so errors like edge stitches dropping or sticking together, some stitches dropping in the middle, or the waste yarn region having failed stitches are all reasonable, just like what you might see in the example photos here.


Questions? Post on Ed Discussion or come to office hours!