Homework Assignment 7

Extending Programs with File Input and Output

CS 1510
Introduction to Computing
Fall Semester 2014

Due: Thursday, October 23, at 10:00 AM


This assignment asks you again to extend a working program with new features. This week, we studied file input and output (I/O), so let's extend a couple of programs to process multiple inputs from files. You will extend the population growth program you wrote for Homework 2 and the body mass index program you wrote for Homework 3.

This assignment requires you to have a working versions of population-predictor.py and body_mass_index.py. If your Homework 2 and 3 solutions do not work correctly, please fix them before starting this assignment. If you feel it would take too long to fix your programs, you may use my solution. E-mail me to let me know you would like to do that.

Download this zip file and use the input files for the tasks below.

I encourage you to personalize your program and make it your own. Feel free to use all the things you are learning in class to make your program as good as you would like. However, be sure not to change the I/O specification, especially the number and order of the data values your program reads from the user.

And, as always, be sure to meet the course programming standards.

Spec 1: Population Growth Predictions

Make a copy of population-predictor.py from Homework 2 and call it population_growth.py. Put the copy in your Homework 7 folder and use the copy for this assignment.

Modify your population growth prediction program to read years from a data file and predict the population in those years. Ask the user for the name of the data file. Write the results to the standard output.

For example, I have a text file called file_of_years.txt that contains the following:


Here is how your program should behave:

    Enter filename: file_of_years.txt

    U.S. Population Forecast from 2014
    Estimated population on 2019/09/05 = 330555324
    Estimated population on 2024/09/05 = 342293602
    Estimated population on 2028/09/05 = 351684224
    Estimated population on 2029/09/05 = 354031879
    Estimated population on 2100/09/05 = 520715417
    Estimated population on 2525/09/05 = 1518468990

I typed file_of_years.txt. The program typed the rest. Your output can look better, if you'd like!

Spec 2: Body Mass Index Calculations

Make a copy of body_mass_index.py from Homework 3. Put the copy in your Homework 7 folder and use the copy for this assignment.

Modify your body mass index program to read patient data from a data file, calculate the body mass index for each, and print the results to a file. Ask the user for the names of the input and output files.

For example, I have a text file called patient_data.txt. Here is how your program should behave:

    Enter input filename : patient_data.txt
    Enter output filename: bmi_report.txt

I typed the two filenames. The result is a new file called bmi_report.txt. Again, you can produce better-looking output, if you'd like.

Demonstration of Correctness

Start a fresh Python shell. Run the final versions of your programs on two input files each:

Save your shell to a text file named interactions.py.


By the due date and time, submit:

Use the on-line submission system.

Make sure that your program meets the course programming standards.

Eugene Wallingford ..... wallingf@cs.uni.edu ..... October 18, 2014