I'm writing a script that calculates a table that produces monthly payment, interest amount, remaining balance, and payment due for each month after taking in an inital purchase price. The code works, but I was wondering if there was any improvements that could be made to this code just for my reference.
***purchasePrice = float(input("Please enter the purchase price: "))
downPayment = purchasePrice * .10
interestRate = 0.12
loanAmount = purchasePrice - downPayment
monthlyPayment = loanAmount * 0.05
currentBalance = loanAmount
month = 1
header = (f"{'Month':<6}{'Balance':<15}{'Interest':<15}{'Principal':<15}{'Payment':<15}{'Remaining Balance':<15}")
print(header)
while currentBalance > 0:
interestOwed = currentBalance * (interestRate / 12)
principalOwed = monthlyPayment - interestOwed
if principalOwed > currentBalance:
principalOwed = currentBalance
payment = principalOwed + interestOwed
currentBalance = 0
else:
payment = monthlyPayment
currentBalance -= principalOwed
print(f"{month:<6}{loanAmount:<15.2f}{interestOwed:<15.2f}{principalOwed:<15.2f}{payment:<15.2f}{currentBalance:<15.2f}")
month +=1
loanAmount -= principalOwed