Question: PYTHON PROGRAMMING LANGUAGE PART 2 remaining_payments() Parameters the balance of the mortgage (the part of the principal that has not been paid back yet; should
PYTHON PROGRAMMING LANGUAGE
PART 2
remaining_payments()
Parameters
the balance of the mortgage (the part of the principal that has not been paid back yet; should be a positive number) the annual interest rate (should be a float between 0 and 1) the payment amount (the amount the user wants to pay per payment; should be a positive number) the number of payments per year (should be a positive integer; default value: 12)
Functionality
Compute and return the number of payments required to pay off the mortgage. We will do this by simulating payments one at a time until the balance of the mortgage reaches zero, assuming fixed payments (in other words, assume that each payment is the same amount of money as the previous one). Note that a mortgage payment is broken down into two parts: an interest payment, and a part that pays down the balance of the mortgage. The interest payment is calculated as described under interest_due(); the rest of the payment goes toward the balance of the mortgage. The percentage of the payment that goes toward interest decreases with every payment because it depends on the balance of the mortgage, which also decreases with every payment. Here is an algorithm for simulating payments until the mortgage is paid off: Initialize a counter with a value of zero; this counter represents the number of payments to be made. As long as the balance of the mortgage is positive, do the following: Use the interest_due() function to determine what portion of the next payment will be interest. The total payment minus interest due is the amount that will go toward paying the balance of the principal. Remember, these amounts will change with every payment. Reduce the balance by the part of the payment that goes toward paying the balance. Increase the counter. When the balance of the mortgage is no longer positive, the value of the counter is the number of payments required. Return this value.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
