From 16ce241169f61712c2b0069529d247493aa75dfd Mon Sep 17 00:00:00 2001 From: - <-> Date: Fri, 9 Feb 2024 19:45:45 -0800 Subject: [PATCH] fixed total payment when one-time payments are applied --- amort.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/amort.py b/amort.py index b9bb39a..71aae2c 100644 --- a/amort.py +++ b/amort.py @@ -33,12 +33,13 @@ def generate_amortization_schedule(principal, interest_rate, loan_term, one_time if remaining_balance < 0: principal_payment = principal_payment + remaining_balance + monthly_payment = monthly_payment + remaining_balance remaining_balance = 0 # Create a dictionary with payment details and add it to the amortization schedule payment_details = { 'Payment Number': payment_number, - 'Payment Amount': monthly_payment, + 'Payment Amount': round(monthly_payment,2), 'Interest Payment': interest_payment, 'Principal Payment': round(principal_payment,2), 'Remaining Balance': round(remaining_balance,2) @@ -76,13 +77,22 @@ if __name__ == "__main__": schedule = generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment) + total_paid = 0 + total_interest_paid = 0 + total_principal_paid = 0 + # Display the amortization schedule print("id, paid, interest payment, principal payment, remaining") for payment in schedule: # print(payment) + total_paid += payment["Payment Amount"] + total_interest_paid += payment["Interest Payment"] + total_principal_paid += payment["Principal Payment"] if payment["Remaining Balance"] < 0: break attrs = [payment[key] for key in payment] print("%s" % ", ".join([str(attr) for attr in attrs])) - + print("total paid: ", round(total_paid,2)) + print("total interest paid: ", round(total_interest_paid,2)) + print("total principal paid: ", round(total_principal_paid,2))