loan calculator

# loan calculator
total = 16000  # Initial loan amount
payment = 400  # Monthly payment
annual_interest_rate = 0.095  # Annual interest rate (5%)
monthly_interest_rate = annual_interest_rate / 12  # Monthly interest rate
months = 0

while total > 0:
    # Adding interest to the total
    interest = total * monthly_interest_rate
    total += interest

    # Making a payment
    total = total - payment
    months += 1

    # Avoiding negative balance
    if total < 0:
        total = 0

    print(f'Owed after month {months}: {total:.2f}')

years = months / 12
print(f'Paid off in {years:.2f} years')

Last updated