Saturday, September 19, 2015

Lab 4x Hello Python - Loan payment, see question 30 on page 370 show payment No. , interest, principal, unpaid balance, total interest to date (do not worry about the output format too much, e.g. how to change 1.234 to 1.23)

def setup():
    loan_amount=5000
    interestRate=12
    months=12
    cal_loan(5000,12,12)
   
def cal_loan(loan_amount, interestRate, months):
    n=1
    term=1
    total_interest=0
   
    effectiveInterest=interestRate/(100*12)
   
    monthlyPayment=loan_amount*(effectiveInterest/(1-pow(1+effectiveInterest,-months)))
   
    balance=loan_amount
    print("Loan Amount $ = ",loan_amount)
    print("Loan Term = ",months," month(s)")
    print("Interest Rate = ",interestRate,"%")
    print("Payment per months = ",monthlyPayment)
    print("Payment No. |  Interset  |  Principal  |  Unpaid Balance  |  Total Interest to Date")
   
    while(term<=months):
        interest = effectiveInterest*balance
        principal=monthlyPayment-interest
        balance=balance-principal
        total_interest=total_interest+interest
        print("     ",term,"        $",interest,"        $",principal,"    $",balance,"           $",total_interest)
        term=term+1
  
setup()

No comments:

Post a Comment