Assignment Problem:
When you take a loan from a bank, they will charge an interest based on the amount of the loan. When you repay the loan yearly, the accrued interest based on the initial amount would be deducted from the repayment and the remainder would be used to repay the loan.
Year
|
Amount
|
Payment
|
Interest
|
Amount Left
|
1
|
$1,000
|
$100
|
$60
|
$960
|
2
|
$960
|
$100
|
$57.60
|
$917.60
|
3
|
$917.60
|
$100
|
$55.06
|
$872.66
|
...
|
...
|
...
|
...
|
...
|
16
|
$68.96
|
$73.10
|
$4.14
|
$0
|
In this example, you took a loan of $1000 with interest rate of 6% per annum compounded yearly. You decide to repay $100 dollars per year. In the first year, the interest of $60 dollars would be deducted from your repayment. The remaining $40 would be deducted from his loan and the current amount you must pay back is $960. The calculations for the subsequent years are shown on the table above.
Write a function loan_amount_left(amount, rate, payment, year) that takes in four inputs: the amount of loan at the start, the annual interest rate, the yearly payment, and the number of years. We assume that the amount is compounded yearly, at the end of the year, after interest is added. Additionally, we assume that the payment is made at the end of the year. The function returns the amount of loan left at the end of the given year.