edX_MITx_6.00.1x/Problem_Set_2/Paying_Debt_Off_in_a_Year.py

def calculate_balance(balance, annualInterestRate):

    monthlyInterestRate = annualInterestRate / 12.0
    remainingBalance = balance
    minimumMonthlyPayment = 0

    while True:
        minimumMonthlyPayment += 10

        for _ in range(0,12):
            monthlyUpaidBalance = remainingBalance - minimumMonthlyPayment
            remainingBalance = round(monthlyUpaidBalance + (monthlyInterestRate * monthlyUpaidBalance),2)

        if remainingBalance < 0:
            break
        else:
            remainingBalance = balance

    print("Lowest Payment: {}".format(minimumMonthlyPayment))

calculate_balance(balance, annualInterestRate)

Leave a Reply

Your email address will not be published. Required fields are marked *