My code:
monthlyInterestRate = annualInterestRate/12.0
low = balance/12
high = (balance*(1+monthlyInterestRate)**12)/12
guess = (low+high)/2
unpaidBalance = balance
month = 1
while True:
unpaidBalance= unpaidBalance-guess
while month < 13:
if unpaidBalance <= -0.1:
low = guess
month += 1
elif unpaidBalance >= 0.1:
high = guess
month += 1
else:
break
guess = (low + high)/2
print "Lowest Payment: " + str(round(guess, 2))
When I test it it gets stuck at the line "while month < 13:"
Why does it do this and how do I fix it?
here you are
No is the best solution, but it works
If you break at each loop of inner while, you remains less than 13.
And this goes on and on since you proceed
While True
and do not update yourguess
.I fear you are facing infinite looping there.
Your
break
statement breaks the closest loop, that is theWhile month < 13
loop. The next line is not read.guess
is not updated. Thewhile True
is not broken.Maybe you wanted to say