0

I did a work for school which I had to submit on a website that verificated if the output requested matched mine. Well,the program is about compond interests: I had to create something that given a certain debt,interest and number of years without paying would print,for every year the acumulating debt.

Everything was just fine until I got a value of 850.85 when it should be 850.86. It is really annoying because due to this round error the code is checked as wrong and I will have 0 on this. Can you help me figuring out what is wrong?

ValorInicial=float(input())#inicial debt

Juro=(int(input()))#interest on a scale 1 to 100

AnosNãoPagos=int(input())#years without paying

Taxa=(Juro/100)

print("Crescimento da divida ao longo de",AnosNãoPagos,"anos:")

print(ValorInicial)

while AnosNãoPagos!=0:

    ValorInicial=ValorInicial+ValorInicial*Taxa

    AnosNãoPagos=AnosNãoPagos-1

    value=round((ValorInicial),2)

    print(value)
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
  • Possible duplicate of [How to round down to 2 decimals with Python?](https://stackoverflow.com/questions/20457038/how-to-round-down-to-2-decimals-with-python) – nicooo21 Oct 20 '18 at 17:39
  • Financial calculation problems should have the exact rounding rules specified. Otherwise, grading the result may be unfair. Perhaps you should be rounding `ValorInicial` to some unknown number of places. Perhaps you should use banker's 'round-to-even'. Perhaps the expected values were calculated with a different Python version than yours. (Round changed a bit in 3.0.) Perhaps you should not update Valor Inicial but use `Valor = ValorInicial * (1 + Taxa) ** . The point here is that expressions equivalent in real numbers are not equivalent in floating point. – Terry Jan Reedy Oct 20 '18 at 18:53
  • In possible, you should talk to instructor about under-specified problem requiring over-exact answer. – Terry Jan Reedy Oct 20 '18 at 18:54
  • I will then. I used python 3.6. I am still a beginner so I might be doing some other errors which I aint aware of but thank you for your advice. – Ana Helena Vieira Oct 20 '18 at 19:05

1 Answers1

0

The problem I see is that taxa is using integer math. In order to fix it change second line to:

Juro=(float(input()))