Code Toolkit: Python, Spring 2026

Week 12 — Homework assignment

due: Tue, November 21, 8pm

  1. Review the class notes for this week.

  2. Modify your dictionary lookup program from last week so that any new definitions added by the user are saved from one run of the program to the next. To do this, when the program exists, save your dictionary as JSON into a file. You will have to modify your program so that when it starts, it first loads this JSON file into your dictionary. You can either manually create a JSON file by hand to start (you could put the definitions you started with last time in here) or add code to check whether the JSON file exists.

  3. Create a simple Processing sketch that changes based on user interaction, and then use JSON to save the state of the sketch and reload when you re-open it. Use the code snippet from Section V of the class notes as an example. Note how that brings together everything that we were talking about in the class notes yesterday: it calls import json, then uses open() to read the contents of a file, then uses json.loads() to interpret the contents of that file as a JSON string, and then finally uses a while loop to iterate over the data structure that comes from loading the JSON string.

    As an example, you can also consider referencing the Week 6 homework that added a new item to a "herd of creatures" every time the user pressed a key.