Unit Wrap-Up Assignment (Not a Deliverable):
Objective: Create an amortization schedule that shows the monthly payments, interest paid, and loan balance for each month.
Description: Modify the loan calculator example provided in the course notebook so that it can repeat the calculations for all of the months the user wants to see results for, and not just only one month. Amortization schedules are commonly used for mortgages, auto loans, and other installment loans, helping borrowers understand how their payments are structured over time.
- Add the below line to the “Get the loan details” section, hardcoding the number of months to calculate the amortization schedule for.
python
1months = 60- Add the below for loop before the interest accrued is calculated since this amount will change each month based on how much is owed. (Note: the months variable represents the number of months to calculate the amortization schedule for.)
python
1for month in range(months):- Indent the subsequent lines of code so that the calculations can be repeated inside the for loop.
- Add the below if statement so that the owed value in the loanBalance variable never goes negative. (Note: the if statement should be placed directly before the Make Payment calculation.)
python
1if (loanBalance - payment < 0):
2 print("The last payment is", loanBalance)
3 print("You paid off the loan in", month + 1, "months")
4 break- A. Within the if block illustrated in the code cell above, convert the
loanBalancevariable in the first print statement to an f-string and format the expression so that 2 decimal places are shown when the expression evaluates at run time.
- Format the month number, monthly payments, interest amounts, and loan balance in four columns as shown in the solution output. (Note: the month number should be month + 1, since month starts counting at 0.)
Solution Example:
- Solution output (displaying the beginning and ending amounts) using the following input parameters:
- loanBalance = $50,000
- apr = 3
- Payment = $1,000
- Months = 60
| Month | Monthly Payment | Interest Paid | Loan Balance |
|---|---|---|---|
| 1 | $1,000.00 | $125.00 | $49,125.00 |
| 2 | $1,000.00 | $122.81 | $48,247.81 |
| 3 | $1,000.00 | $120.62 | $47,368.43 |
| 4 | $1,000.00 | $118.42 | $46,486.85 |
| 5 | $1,000.00 | $116.22 | $45,603.07 |
| 6 | $1,000.00 | $114.01 | $44,717.08 |
| 7 | $1,000.00 | $111.79 | $43,828.87 |
| 8 | $1,000.00 | $109.57 | $42,938.44 |
| 9 | $1,000.00 | $107.35 | $42,045.79 |
| 10 | $1,000.00 | $105.11 | $41,150.90 |
| --snip-- | --snip-- | --snip-- | --snip-- |
| 51 | $1,000.00 | $8.65 | $2,468.55 |
| 52 | $1,000.00 | $6.17 | $1,474.72 |
| 53 | $1,000.00 | $3.69 | $478.41 |
| The last payment is $479.61 | |||
| You paid off the loan in 54 months | |||