From 2bf6ec00e22d9ee9de6fb1ff4b521290bc0b0054 Mon Sep 17 00:00:00 2001 From: - <-> Date: Fri, 9 Feb 2024 16:47:56 -0800 Subject: [PATCH] subtract from principal payment if remaining balance < 0 --- amort.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/amort.py b/amort.py index 17ab4cd..b9bb39a 100644 --- a/amort.py +++ b/amort.py @@ -1,3 +1,4 @@ + import argparse, json def generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment=None): @@ -30,6 +31,10 @@ def generate_amortization_schedule(principal, interest_rate, loan_term, one_time # Update remaining balance remaining_balance -= principal_payment + if remaining_balance < 0: + principal_payment = principal_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, @@ -47,7 +52,6 @@ if __name__ == "__main__": # principal = 100000 # interest_rate = 5.0 # loan_term = 3 - # def get_arguments(): p = argparse.ArgumentParser() p. add_argument("--principal", "-p", type=float, \ @@ -73,10 +77,12 @@ if __name__ == "__main__": schedule = generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment) # Display the amortization schedule + print("id, paid, interest payment, principal payment, remaining") for payment in schedule: # print(payment) if payment["Remaining Balance"] < 0: break attrs = [payment[key] for key in payment] - print(attrs) + print("%s" % ", ".join([str(attr) for attr in attrs])) +