i am doing the MITx 6.00.01x course and i am on the second problem set on the 3rd problem and i am stuck. my code:
balance = 320000
annualInterestRate = 0.2
monthlyInterestRate = (annualInterestRate) / 12.0
monthlyFixedPayment = 0
empBalance = balance
lowerBound = round((balance)/12,2)
upperBound = (balance*(1+monthlyInterestRate)**12)/12
monthlyFixedPayment = round( ( (lowerBound+upperBound)/2) ,2)
while tempBalance != 0:
monthlyFixedPayment = round( ( (lowerBound+upperBound)/2) ,2)
for m in range(12) :
tempBalance -= monthlyFixedPayment
tempBalance += (monthlyInterestRate)*(tempBalance)
tempBalance = round(tempBalance,2)
if tempBalance > 0:
lowerBound = round(monthlyFixedPayment,2)
tempBalance = balance
elif tempBalance < 0:
upperBound = round(monthlyFixedPayment,2)
tempBalance = balance
print('Lowest Payment: ' + str(round(monthlyFixedPayment,2)))
my code uses bisection search to generate the monthlyFixedPayment but after i get to the lines at the end that changes the upperBound or lowerBound values and then start the loop again, the lowerBound and upperBound values reset to their values to the ones outside the loop. does anyone knows how to prevent this?