python - Program stops working with inputs above 8000 -
i wrote following credit card program in response question on site (credit card balance exercise in python):
def main(rb): count = 0 while rb > 0: rb = rb*(0.18/12 + 1) - 120 count += 1 return count, round(rb, 2) print(main(input('balance: '))) #balance: 1200
it calculates number of repayments made , final balance. op interested in original balance of 1200 changed user can input own original balance. value of 8000 , below answer comes in fraction of second. above 8000 no answer comes ever. terminal stays blank. i've never come across behaviour before. baffled this. can replicate it? why happen?
you can see why hangs stepping through loop once rb = 8001
.
8001 * (0.18 / 12 + 1) - 120 ~= 8001.014999999999
with values <= 8000, value decreases, values > 8000, value increases rb >= 0
true.
Comments
Post a Comment