CS100: Project 0

Revision Date: January 8, 2017

Printable Version


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

Let's get vertical, vertical

Imitation is the sincerest form of flattery - Aesop

Real Computer Scientists abhor reinventing the wheel. So when given the task of writing a program, they search out and find programs they feel are similar to the one they need to write. They then modify the program, with permission, so that it processes the input and produces the output they desire. They accomplish this feat even if they do not completely understand the original program upon which they are basing their new program.

Your task is to take an existing program that computes MLB slugging percentage and turn it into a program that computes NCAA passing efficiency.

Where to start

The first thing you should do is to setup a directory in which you will work. Run the following commands, one at a time:

    cd cs100
    mkdir project0
    cd project0

The first two commands move you into your cs100 directory, while the next two create and move into a project directory. Now, retrieve the existing program for computing slugging percentages (Major League Baseball formula) with the command:

    wget troll.cs.ua.edu/cs100/python/projects/slugging.py

Run the program, using the command:

    python3 slugging.py

In another terminal window, move into your project directory and run the command:

    vim slugging.py

This will allow you to look at the program while it is running in the other window. Try to figure out what part of the code does what by running the program in the other window over and over.

How to proceed

Now, in the first window, copy the existing program over into a new file named passing.py with the command:

    cp slugging.py passing.py

In the second window, quit vim and open up the new file, passing.py. Now begin modifying passing.py so that it stops computing MLB slugging percentage and starts computing NCAA passing efficiency. Make one change at a time and test after each change. Don't forget the vim's undo button in case you introduce an error into the code. Once a change is working, make sure you save the file.

You can see the formula for computing MLB slugging percentage at http://en.wikipedia.org/wiki/Slugging_percentage and the formula for computing NCAA passing efficiency (sometimes known as passer rating) at http://en.wikipedia.org/wiki/Passer_rating.

Compliance Instructions

Create a file named test0 that contains five numbers for which your new program prompts. The numbers should be in the same order as those shown on the Wikipedia page: yards, touchdowns, completions, interceptions, and attempts.

Now, make sure that you have implemented your program correctly by running this command:

    cat test0 | python3 passing.py

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.

Your program should print out clearly the results consistent with the five inputs. If your code fails with a runtime error while running this test, then you will receive a zero for this assignment.

Note that your answers do not have to be correct for your program to be graded, only that the program does not crash. Of course, correct answers will yield a much higher grade.

Note also that a prerequisite for receiving full credit is that your new program be based off the original program.


Try to get numbers to print like 1.324 instead of 1.3235294117647058.

Try to get quantity agreement between numbers and their labels. For example, the slugging program, in the case of one homer, would display:

    1 homers

instead of:

    1 homer

Submission Instructions

Change to the project0 directory containing your assignment. Do an ls command. You should see something like this:

    slugging.py   passing.py  test.dat

Extra files are OK, as long as you are in the correct directory. (Submissions from the wrong directory that include many extra files will be penalized.) You will not be penalized if you submit files unrelated to this project.

Submit your program like this:

    submit cs100 YYY project0

Remember to replace YYY with your section number. Note that project0 ends in a zero, not a capital Oh.