Code Toolkit: Python, Fall 2025

Week 12 — Homework assignment

due: Tue, November 18, 8pm

  1. Review the class notes for this week.

    Please note: We have a reading to prepare for discussion this week. Check the schedule page (under week 13).

  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. (Update: Focus on parts 1 & 3, and consider part 2 as optional.) Modify your guessing game from last week to add a "high score list"? When the game ends, attempt to load a JSON file with a high score data structure, or if it does not exist, create one. Add the user's name and score (number of guesses) to the data structure and print it. Then save the modified score list to a JSON file.

  4. 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.