Optional
Develop an online saving compound interest calculator. The calculator allow student to input deposit amount and interest rate. Student can have the option to save additional amount every year.
The formula for an interest calculation:
A = P(1 + r ) A = final amount P = Initial principal r= annual interest rate
A student wrote a simple code as below to computes the total saving after 3 years.
deposit = int(input('Enter deposit amount: '))
addition = int(input('Enter annual addition: '))
rate = float(input('Enter interest rate: '))
savingYr1 = deposit * (1 + rate*0.01)
savingYr2 = deposit + addition * (1 + rate*0.01)
savingYr3 = savingYr2 + addition * (1 + rate*0.01)
print('Total saving at year 3: ${:,.2f}'.format(savingYr3 ))
If the input entries are :
Initial deposit = $2000 Additional = $2000 Interest rate = 2.5%
The expected outcome must be :
Total saving = $6305.03
Use the debugger to trace the saving computed by the program to compare again the expected value.
Year | Expected saving at the year | Use debugger to find the value of the saving |
---|---|---|
1 | 2050.0 | |
2 | 4151.25 | |
3 | 6305.031249999999 |
What is the observation?
Examine the code to fix this logic error.