# 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


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.

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.

SyntaxError Exceptions A program that doesn’t even start due to syntax errors. -30
main() Your program should have main() as the first-called function -10