Sequences

It’s time to work with sequences! Files, lists and strings…oh my!

Programmer joke: Why do programmers always mix up Halloween and Christmas? Because Oct 31 equals Dec 25!

Your Assignment

You are given a small text file containing financial data. This data was created using a modified version of the futval.py example. Your job is to write a program to read in this text file containing data and print out its information in a clear, human-readable fashion.

You will use indexing (maybe slicing), string methods, file input, string-to-numerical conversions and Python string formatting (as well as concepts learned in past weeks).

Your program is required to do the following:

  1. Print a short introduction about what this program does.

  2. Ask for a filename to open for reading.

  3. Open the file using the given filename, and then read in the text file. It has a specific format:

    • Line 1 always has the format years <integer value>, e.g. years 10.

    • Line 2 always has the format principal <decimal value>, e.g. principal 1000.00

    • Line 3 always has the format interest <decimal value>, e.g. principal 0.035

    • Line 4, and all remaining lines of the file will be just a decimal number, one per line, e.g.:

      1000.00
      1102.32
      1302.42
      

    Download and place* data.txt in the same location as your Python program. That way, you avoid any issues with specifying pathnames to files and all the nuances that involves.

  4. After reading the file, I want you to extract the information about the years, principal, interest and all the balances for each year of accrual of interest, stored in variables in your program for later use. Expect to convert those extracted bits of information into the right Python data types (whether they are a list of float numbers, single float or int values, etc.)

  5. Using the extracted information, you need to print out a nice table. The decimal numbers should have two places of precision, the monetary values have a dollar sign for U.S. Dollars, and the percentage rate is printed as a percentage value, not a simple decimal number. You will use Python string formatting to format the table nicely.

  6. Once you are finished reading from the file, you need to properly close your file.

Output

This program reads in financial information from a file
and prints it neatly to the user's screen.

Please enter the filename of the financial data: data.txt

The initial principal is: $42420.00
Annual percentage rate is: 4.2%
Length of the term (years): 10

Year    Value
------------------
  0     $42420.00
  1     $44201.64
  2     $46058.11
  3     $47992.55
  4     $50008.24
  5     $52108.58
  6     $54297.14
  7     $56577.62
  8     $58953.88
  9     $61429.95
 10     $64010.00

Submission Requirements

Your file is required to be named lab_sequences.py.

Please read and follow the Submission Requirements to avoid point deductions specified below.

Grading

The following is the grading rubric for this lab to be used by the course graders. The lab is worth 100 points.

Note: There may be additional criteria for grading, this is just a summary of the major rubric items.

Grading Rubric
Type Description Point Loss (Max)
  [General]  
SyntaxError Exceptions A program that doesn’t even start due to syntax errors. -30
Docstrings Missing proper lab header (e.g. no name, lab section, etc) -10
main() Your program should have main() as the first-called function -10
PEP 8 Style Egregious problems with your code styling -10
Incorrect Filename Follow the submission instructions -5
Commenting Insufficient or excessive comments -5
  [Lab Specific]  
Filename Not asking for a filename to read -10
File Handling Not properly opening and closing a file for reading -10
Parsing Not using techniques taught in class to extract information from the data fil -20
Output Your printed table of information is not properly formatted (and it must use Python string formatting techniques): -20