0

I'm learning to code in python and I created a code to calculate the amount of a debt its compound interest and the instalments to pay the debt. The code works fine with small amounts but if I go over 10k with the debt the program gets into an infinite loop, can anyone help?

Code below:

print('Debt')

a = float(input('Debt amount: $ '))
b = float(input('interest rate: % '))
c = float(input('monthly instalment: R$ '))
b /= 100
x = 0
div = a
ttp = 0

while div > 0:
    inte = div*b
    div = (div + inte) - c
    x += 1

ttp = (c*x) + div
print ('The total of months to pay out the debt was: %d\nThe total paid was: R$%.2f ' % (x, ttp))
print('The total paid in interest was: $ %.2f' % (ttp-a))
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    Try putting `print(div)` in the loop and see what the values are. – Barmar Aug 06 '20 at 16:19
  • I think for very high value the rate of inte is higher where as the subtracted C remains constant. – Krishna Srinidhi Aug 06 '20 at 16:20
  • I've tried print(div) with low amounts it goes perfectly but with an amount over 10k it goes in an eternal loop, if you can run the code you'll see. Try with a=1000, b=1, c = 50. It will calculate it and give the right answer. But if you try a=10000, b=1, c = 500, then will be an eternal loop – Bruno Prandi Aug 06 '20 at 16:33

0 Answers0