Question: implement the compound_interest helper function. You may recall the following formula from the preceding unit: A: final amount P: initial principal balance r: interest rate
implement the compound_interest helper function. You may recall the following formula from the preceding unit:
A: final amount
P: initial principal balance
r: interest rate
n: number of times interest applied per time period
t: number of time period elapsed
Here, you will also have to account for the situation when the interest is compounded continuously according to the following formula:
The compound_interest 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.
years: An int indicating the number of years elapsed.
The compound_interest function returns the amount that is going to be on the account after the specified number of years based on the provided parameters. So, there are two situations to account for:
When acc_cmp_freq is 0, the interest is compounded continuously (use the second formula). Note that we can't use the first formula since we would arrive at a division by zero error.
When acc_cmp_freq is not equal to 0, then the interest is compounded as shown by the first formula.
For more details on computing compound interest, please, refer to this tutorial.
You are encouraged to validate your implementation by placing several calls to the compound_interest as shown below:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
