Homework Assignment 8
An Inventory Management Program
Introduction to Computing
Fall Semester 2014
Due: Monday, November 3, at 10:00 AM
For this assignment, you will write a new program from scratch.
The focus is writing functions and practicing more with file
Spec 1: Inventory Management
Your client this week is a candy bar distributor that caters to
the nostalgia market. This small company distributes just four
products: Chunky, Skybar, Valomilk, and Zagnut. It needs a
simple program to help it track its inventory of these vintage
The program uses three text files:
- the initial inventory,
- the week's transactions, and
- the updated inventory.
Each inventory file consists of four lines, one per product.
Each line contains a product name followed by the number of
cases of that product in the warehouse. The name and number are
separated by whitespace. The order of the four products in the
file is not specified; neither is the case used for the candy
bar name. For example, here are two possible input files:
example one example two
Chunky 12 ZAGNUT 8
Zagnut 8 VALOMILK 3
Skybar 19 SKYBAR 19
Valomilk 3 CHUNKY 12
The transaction file lists all the transactions for the week,
both sales to customers and purchases from candy manufacturers.
Each line of this file consists of the data for a single
- A sale transaction line contains, in order, the word
sale, one of the four product names, and
a positive whole number of cases of this product sold to
- A purchase transaction line contains, in order, the word
purchase, one of the four product names,
and a positive whole number of cases of this product
purchased from a manufacturer.
As with the inventory files, the data on each line are
separated by whitespace, and the case used for the transaction
types and candy bar names is unspecified. For example, here
are a few possible transaction lines:
sale chunky 1
PURCHASE ZAGNUT 8
Sale zagnut 8
SALE VALOMILK 3
Purchase chunky 5
The program must take the following input from keyboard:
- the name of the file with the week's beginning
- the name of the file containing the week's transactions,
- the name of the file in which to write the week's closing
In addition to producing an output file that lists the week's
closing inventory, the program must also print to the screen:
- a table displaying the week's beginning inventory,
- the number of sales transactions processed,
- the number of purchase transactions processed, and
- a table displaying the week's ending inventory.
You may assume the following:
- The user enters valid file names.
- The input files exist.
- The data in the input files conforms to the specifications
- A sale transaction never results in a negative inventory
Here is some design and programming advice:
- Create several input files to test your program. Verify
the results by hand. (I will use test data files that
are too large to make hand calculation of the results
- Break the problem into high-level operations that need
to be done. Implement and test each, one at a time.
- Use functions to implement your high-level operations.
This will make your program easier to understand, and it
will enable you to avoid duplicating code. For example,
your program needs to display to the screen both the
beginning inventory and the closing inventory. A single
function can do both.
- Give your functions and formal parameters names that are
clear and descriptive. Use comments to explain any idea
that your names cannot communicate.
- Use the string method split() with no
arguments to break your input lines into parts. Use
parallel assignment to assign the resulting values to
- Close each data file as soon as your program is finished
Name your program candybar_inventory.py.
Demonstration of Correctness
Start a fresh Python shell. Run the final version of
your program on at least three sets of input files for
beginning inventory and transactions. These input files
should demonstrate that your program satisfies the program
Save your shell to a text file named
By the due date and time, submit:
the on-line submission system.
Make sure that your program meets
the course programming standards.
Eugene Wallingford .....
October 26, 2014