Question: In TODO 7 , you will implement the simulate_account_balance function. The function has the following parameters: init_principal: A float indicating the initial principal balance. acc_rate:
In TODO 7, you will implement the simulate_account_balance function. The function has the following parameters:
init_principal: A float indicating the initial principal balance.
acc_rate: A float indicating the interest rate per year (e.g., 0.05 for 5%).
acc_cmp_freq: An int indicating the number of times interest is applied per year.
setup_fee: A float indicating the amount of dollars that is deduced from the init_principal when the account is set up (you only deduct once).
years: An int indicating the number of years for which we would like to run the report.
Based on the provided arguments, the function will print one or more lines each of which displays two values - year number (starting from 2) and current balance on the account - separated by a space.
Let us go over the details of how the function works using the following example arguments:
init_principal: 10000.00
acc_rate: 0.025
acc_cmp_freq: 12
setup_fee: 25.00
years: 10
Overall, the simulate_account_balance function implements the loop that prints the balance on the account each two years. Note that;
The first row should show the balance after 2 years.
The last row should show the balance after the number of years specified under years (or years - 1 if the years argument is an odd number).
We suggest you implement the function in the following flow:
Define a loop that executes years / 2 times assigning the year variable with the even numbers 2, 4, etc. HINT: Consider using the Python in-built range class. class range(stop)
class range(start, stop[, step])
The arguments to the range constructor must be integers (either built-in int or any object that implements the __index__() special method). If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0. If step is zero, ValueError is raised.
For a positive step, the contents of a range r are determined by the formula r[i] = start + step*i where i >= 0 and r[i] < stop.
For a negative step, the contents of the range are still determined by the formula r[i] = start + step*i, but the constraints are i >= 0 and r[i] > stop.
A range object will be empty if r[0] does not meet the value constraint. Ranges do support negative indices, but these are interpreted as indexing from the end of the sequence determined by the positive indices.
Ranges containing absolute values larger than sys.maxsize are permitted but some features (such as len()) may raise OverflowError.
Within each iteration, compute the balance on the account (using the compound_interest function you implemented earlier), and print the year variable and the balance on the account rounded to 2 decimal places.
For example, we get the following lines for; Year 2:
2 10485.88 # compound_interest(9975.00, 0.025, 12, 2) -> 10485.88 Year 4:
4 11022.93 # compound_interest(9975.00, 0.025, 12, 4) -> 11022.93 Year ...:
... (etc.) HINT: For rounding, you may use the Python in-built round function.
>>> round(1.2345, 2) 1.23 >>> round(1.2001, 2) 1.2 Attention
Be careful to properly account for the setup_fee. Think carefully about the point in time when the fee is applied.
You are encouraged to validate your implementation by placing a call to the simulate_account_balance function as; simulate_account_balance(10000.00, 0.025, 12, 25.00, 10)
The expected output of running the file would then be:
2 10485.88 4 11022.93 6 11587.49 8 12180.96 10 12804.82
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
