In: Computer Science
The purpose of this exercise is to give you experience in writing condition-controlled loops.
Create a code in Python that will print monthly loan amortization schedule given the loan amount (P), APR i.e. Annual Percentage Rate (r=APR in %/12), loan terms in number of months (n).
Please use these formulas:
Monthly Payment (A) = P * ((r * (1 + r)**n)/(((1+r)**n)-1))
Monthly Interest Pmt (mIP)= r * Total Remaining Balance
Monthly Principal Pmt (mPP) = A – mIP
Total Remaining Balance (bal) = bal – mPP
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. Let me know for any help with any other questions. Thank You! =========================================================================== def loan_table(loan, apr, month): # initialize values rper = apr / 1200 period = 0 balance = loan payment = loan * (rper * (1 + rper) ** month) / (((1 + rper) ** month) - 1) # print header la = "Loan Amount: $ " ap = "APR: " months = 'Months' payments = 'Payment' print(f"{la: <15s}{balance: <11,.2f}") print(f"{ap: <15s}{apr: <11.4f}") print(f"{months: <15s}{month: <11.2f}") print(f"{payments: <15s}{payment: <11.2f}") print() c1 = "Period (#)" c2 = "MonthlyInterest ($)" c3 = "Monthly Principal ($)" c4 = "New Balance ($)" spacer = " " print(f"{c1: >11s}{spacer}{c2: >15s}{spacer}{c3: >15s}{spacer}{c4: >15s}") # print payment info by period while balance > 0: period += 1 mIP = rper * balance mPP = payment - mIP balance = balance - mPP print(f"{period: <11d}{spacer}{mIP: >15.2f}{spacer}{mPP: >15.2f}{spacer}{balance: >20.2f}") def main(): loan_amount = float(input('Enter loan amount: $')) annual_percentage_rate = float(input('Enter Annual Percentage Rate (%): ')) months = int(input('Enter the number of months: ')) loan_table(loan_amount, annual_percentage_rate, months) main()
====================================================================