CS 100: Project 1

Revision Date: January 8, 2017

Printable Version


You may develop your code anywhere, but you must ensure it runs correctly on a Linux distribution before submission.


It is the function of vice to keep virtue within reasonable bounds. - Samuel Butler

Your task is to read in three numbers and then compute and print some statistics: the minimum, the maximum, and the mean of the three numbers. Then, you are to read in a fouth number and print some information on how the fourth number (let's call it n) relates to these statistics.

If the n is less than the minimum of the first three or greater than or equal to the maximum, your program should print a message indicating that n is out of bounds. If n is not out of bounds, but less than the average of the minimum and the mean, your program should print out a message that n is in the lower region. If the first two cases do not apply and n is less than the average of the mean and the maximum, your program should print a message that n is in the middle region. If none of the previous cases are true, then n lies in the upper region and a message should be printed to that effect.

An Example

Here is a transcript of an interaction testing the out-of-bounds message:

    $ python3 stats.py
    Give me an integer: 2
    Give me another: 10
    And another: 6

    The minimum is 2
    The maximum is 10
    The average is 6.00000

    Give me the fourth integer: 1

    The number 1 is out of bounds.

While the verbiage of the output does not have to match exactly, the spacing of the output does.

Coding Style

You should provide the following functions:

You should not include logic anywhere in your program that duplicates logic implemented in one of the above functions. In other words, you should reuse functions as much as possible. HINT: your main will never explicitly use <, <=, >, or >=.

Test Cases

You are to construct five test cases, named test.oobl, test.oobh, test.lr, test.mr, and test.ur. The file test.oobl should contain the numbers


one number per line, with no blank lines.

To see if your test case is correct, run the command:

    $ cat test.oobl | python3 stats.py

You should see output similar to:

    Give me an integer: Give me another: And another:
    The minimum is 2
    The maximum is 10
    The average is 6.000000
    Give me the fourth integer:
    The number 1 is out of bounds.

This method of running the program is called "piping in the input from a file." When you actually do this, the prompts your program makes for information will all be strung together on a single line. Don't worry about it; it's a natural consequence of the way the program was run.

Now create the other test cases. The extension oobl stands for "out of bounds, lower". From this, you should be able to figure out what test data goes into the remaining files.

The superior student will vary the first three numbers for each test case. In addition, the superior student will provide additional test cases that test the boundary conditions of this problem. In general, boundary conditions can be thought of as where two similar inputs to a program produce dramatically different outputs. For example, for the region 2..10, 5 is in bounds, but so is 6. Thus 5 and 6 do not test a boundary condition. On the other hand, 9 is in bounds but 10 is not (due to the high end being exclusive). In this case, the inputs 9 and 10 do test a boundary.


You will receive a less than perfect score for the following infractions:

Solution Path

One possible path to coding a solution for this problem would follow the following outline:

Submission Instructions

Change to the directory containing your assignment. Do an ls command to make sure you are in the correct place. You should see, at least, your stats.py and associated test files. Extra files are OK. Submit your program like this:

    submit cs100 XXX project1

Remember to replace XXX with your section number.