CS 161 Workshop: Micro-Amazon.com (or, Using Dictionaries and Files)

November 15, 16, 17

 

Imagine you run the informal (and strictly speaking, illegal) snack pantry in your department's student lounge. Every week or two you buy an assortment of snack foods and stock the shelves in the pantry. You post a list of the price you charge for individual items, and leave out a empty coffee can where people can deposit money for the items they take. Despite the fact that students in your department are all honest, you discover you are loosing money. Students often don't have cash with them when they want a snack, so they take something intending to pay later, but forget.

 

You have therefore decided to create a computer system that will allow users to charge purchases to their account and to manage the inventory, so you can easily determine what everyone owes and how much of each snack item is in stock. Your system will have a nice Web interface that works by calling functions in a running Python program. (If you take CS 210 Web Programming next semester, you will learn how this can be done.) You will begin by specifying the underlying Python functions your system will use.

 

Task 1: Break into groups of 4 or 5 students. Each group should come up with a list of the functions that are needed, and what they do. Tasks will include:

Specify the names and parameters of each function. Think of one or more other useful functions, e.g., for calculating profit or generating shopping lists.

 

Task 2: Have the class come back together. Share the specifications from the various groups, and decide on a set of functions to be implemented. Next, discuss and decide on a set of core data structures that will be used to store all the necessary information. Think: dictionaries! Write on the blackboard exactly how each kind of information is stored.

 

Task 3: Each of the subgroups should is assigned some of the functions to implement (different functions for each group). The subgroups write Python code for their functions. When they are satisfied that their functions are in good shape, they should write the function definitions on the blackboard.

 

Task 4: The groups come back together, and the class holds a "code review": will all the functions work together smoothly?