Sequences¶

Lab Assignment: 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!

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.

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


Hint: 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 accural 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. Notice that the decimal numbers have two places of precision, monetary values have a dollar sign for U.S. Dollars, and the percentage rate is printed as a percentage value, not a basic decimal number. You will need to use Python string formatting to format the table nicely.

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

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

Submission Requirements¶

1. Submission Filename: Submit a file named lab_sequences.py.

2. Documentation String (“docstring”): The following docstring (properly edited with your name) needs to be the very first thing in your Python program file.

"""CSC 161 Lab: Sequences

This lab...

Fox Mulder
Lab Section TR 2:00-3:15pm
Fall 2015
"""


3. Comments (lines prefaced with #): Unclear parts of your code can receive point deductions, so be judicious about using comments. Do not overuse comments. Too much unnecessary commenting can complicate reading otherwise clear code!

4. Python Code Style: You will need to run your Python program file through the online PEP 8 style checker found in CSC 161 Style.

The Blackboard post for this lab assignment will contain the details regarding the due date and other details regarding class administration for this assignment.

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

• Syntax errors: -30 points
• A bad/missing docstring (i.e. no name, lab section, etc): -10 points
• Missing main() function: -10 points
• Code doesn’t attempt to adhere to Python coding style: -10 points
• The submitted filename is wrong: -5 points
• No Python comments used when they are needed to clarify code: -5 points
• Missing introduction when your program runs: -10 points