#constants declaration DOWN_PAYMENT_RATE = 0.10 ANNUAL_INTEREST_RATE = 0.12 MONTHLY_PAYMENTS_RATE = 0.05 #prompt the user to enter the purchase price purchasePrice = float(input("Enter the purchase price: ")) #The month number (beginning with 1) month = 1 #The payment for that month payment = purchasePrice * MONTHLY_PAYMENTS_RATE #The current total balance owed startingBalance = purchasePrice #print the table heading print("\n%s%19s%18s%19s%10s%17s" % ("Month", "Starting Balance", "Interest to Pay", "Principal to Pay", "Payment", "Ending Balance")) #repeat the loop as long as the startingBalance is greater than 0 while startingBalance > 0: #The interest owed for that month interestToPay = startingBalance * ANNUAL_INTEREST_RATE / 12 #The amount of principal owed for that month principalToPay = payment - interestToPay #The balance remaining after payment endingBalance = startingBalance - payment #print the statistics print("%2d%16.2f%16.2f%18.2f%18.2f%15.2f" % (month, startingBalance, interestToPay, principalToPay, payment,endingBalance)) #update the starting balance startingBalance = endingBalance #increment the month by 1 month = month + 1
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)