Question
Please help me write a code that satisfies these conditions using Python and include comments since I am very new to coding. You are given
Please help me write a code that satisfies these conditions using Python and include comments since I am very new to coding.
You are given a small text file containing financial data (copied below). 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:
-
Print a short introduction about what this program does.
-
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 years
, e.g. years 10. -
Line 2 always has the format principal
, e.g. principal1000.00 -
Line 3 always has the format interest
, e.g. principal0.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.
-
-
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 floatnumbers, 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 properly close your file
Data text file:
years 10 principal 42420 interest 0.042 42420 44201.64 46058.10888 47992.549452960004 50008.23652998432 52108.582464243664 54297.1429277419 56577.62293070706 58953.88309379676 61429.946183736225 64010.00392345315
The output should look like this:
The printed table of information should be properly formatted using Python string formatting techniques.
Output This program reads in financial information from a flle 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 $42420.00 $44201.64 $46058.11 $47992.55 $50008.24 $52108.58 $54297.14 $56577.62 $58953.88 $61429.95 $64010.00 2 4 6 10Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started