0
Recently I was trying to solve an exercise to learn Python, but I found big problems when I tried to calculate compound interest. I used the mathematical formula of the amount and simply I have no idea what this wrong (in particular with the 27° line. I believe the problem of logic is there, whatever).
Below is my faulty code:
c = float(input('Digite o depósito inicial: R$'))
i = float(input('Agora, digite a taxa de juros de uma poupança: '))
t = 1 # Contador dos meses
c2 = None
while t <= 24:
m = c * (1 + (i / 100)) ** t
if t == 1:
print(f'\nNo mês {t}, o valor dos juros será igual a R${m:.2f}')
else:
print(f'\nNo mês {t}, o valor dos juros será igual a R${m:.2f}')
if t == 24:
break
t = t + 1
op = input(f'Deseja realizar um depósito para o {t}° mês[S/N]? ').strip().upper()[0]
while op != 'S' and op != 'N':
op = input(f'OPÇÃO INVÁLIDA! Deseja realizar um depósito para o {t}° mês[S/N]? ').strip().upper()[0]
if op == 'S':
c2 = float(input(f'Digite o valor do depósito do {t}° mês: R$'))
else:
c2 = 0
c = c2 + m
j = c * (1 + (i / 100)) ** t
print(f'No total, a quantidade de reais ganha com os JUROS COMPOSTOS será igual a R${j - c:.2f}')
I sought some references to the solving this problem, especially the blog post of Professor Nilo, author of the book "Introduction to Pyhton Programming - Algorithms and Programming Logic for Beginners", where is this exercise (Being more specific, is the 5.12 of 5° chapter)
IMPORTANT DETAIL: I noticed that, in the link above, the teacher DOES NOT use the conventional mathematical formula of the Amount, but I just don’t understand why
For self-correction, I used several websites, but the main compound interest simulator was this:
I couldn’t help but notice that the "punctuation" of my question fell. Please leave suggestions below, so that I can clarify the passages that were confused and improve the understanding of my question
– Rodrigo1X