Only the compilation of your submitted code will be tested. No tests have been added yet to check if your code also performs the required tasks. Your last submission will be improved using automated tests and also manually by the instructor.
An annuity is a fixed amount that is periodically paid or received over a certain period. Literally, an annuity is an amount to be paid annually. It is derived from the Latin word “annus” (year). This same principle can, of course, be applied to other time intervals. If the monthly payment amount needs to be calculated, it is called an annuity. In this exercise, you will write a program that creates an amortization table so that the user can quickly see how much they have to pay each year to repay their loan.
Define a function annuity with parameters the borrowed amount, the interest rate, and the number of years over which the loan is taken. This function returns the annuity using the formula below. In this formula, \(A\) represents the annual payment amount (the annuity), \(T\) represents the total borrowed amount, \(I\) represents the interest rate (represented as a number between \(0\) and \(1\), for example, \(0.05\) corresponds to \(5\%\)), and \(P\) represents the period over which the loan is taken (for example: 5 years).
\[\text{A} = \frac{T * I}{1 - (1 + I)^{-P}}\]An annuity always consists of an interest part and a principal part. The interest part and the principal part can be calculated as follows:
\[InterestPart = RemainingPrincipal * InterestRate\] \[PrincipalPart = Annuity - InterestPart\]Define a function _amortization_table_print with the same parameters as the annuity function. The function calculates the amortization table using the amortization table functions and then prints the amortization table to the console as shown in the example. All amounts are rounded to two decimal places.
amortization_table_print(50000, 0.05, 5)
+------+----------+----------+----------+
| 1 | 11548.74 | 2500.00 | 9048.74 |
| 2 | 11548.74 | 2047.56 | 9501.18 |
| 3 | 11548.74 | 1572.50 | 9976.24 |
| 4 | 11548.74 | 1073.69 | 10475.05 |
| 5 | 11548.74 | 549.94 | 10998.80 |
+------+----------+----------+----------+