Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given a small text file containing financial data. Your job is to write a program to read in this text file containing data

You are given a small text file containing financial data. 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:

Ask for a filename to open for reading.

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 principal , e.g. principal 1000.00

Line 2 always has the format interest , e.g. interest 0.035

Line 3 always has the format years , e.g. years 10.

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.

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.)

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.

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

Notes

1. All printed strings must match the above output. To otherwise deviate will cause the Gradescope autograder to deduct points.

2. Use formatting to make sure the output matches up, in particular, pay attention to:

- The initial principal and all monetary values are formatted to 2 decimal places.

- The percentage is formatted to 1 decimal.

- There is an empty line between entering the filename and then printing the principal, interest, and years, and then another gap before printing the yearly balance.

- Year is 4 characters long, all years will be at most 4 characters long (and they are formatted to always take up 4 spaces).

- There is a space between Year and Value as well as a space between the year and the yearly balance.

3. The only input that is typed in is the filename, the principal, percentage, number of years, and the data comes from reading the file. If you're stuck on reading from the file you can start with getting input for all of these values, and then change the program later.

image text in transcribed

Output Please enter the filename of the financial data: data.txt The initial principal is: $1000.00 Annual percentage rate is: 3.4% Length of the term: 10 Year Value 0$1000.00 1$1034.00 2$1069.16 3$1105.51 4$1143.09 5$1181.96 6$1222.15 7$1263.70 8$1306.67 9$1351.09 10$1397.03

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions