Home>

I'm sorry for the rudimentary question about Python's For statement,
The following formula does not show why the compounding of the principals (Savings) is calculated.

savings = 100
for i in range (15):
    savings + = savings * 0.05
print (savings)


This result is about 207.9 (15-year compound interest calculation with a principal of 100 and an interest rate of 5%).
If savings + = savings * 0.05, then 100 + 100 * 0.05 would be 105, and that would be repeated 15 times.

  • Answer # 1

    saing changes in the loop.
    Try executing the print statement.

    savings = 100
    for i in range (15):
        print (savings)
        savings + = savings * 0.05
    print (savings)


    Execution example

  • Answer # 2

    15% interest rate of 15% Since the annual compounding calculation,savings + = savings * 0.05can be rewritten assavings * = 1.05. You will see whether savings * 0.05is fine.

    As Katoy mentioned,savingsis avariablethat changes with each loop.

    savings = 100
    for i in range (15):
        savings * = 1.05
        print (savings)
    print (savings)

  • Answer # 3

    savings + = savings * 0.05 is

    Savings = savings + savings * 0.05

    If you transform the formula
    You can also write savings = savings * 1.05

    If this is the case
    It is the definition of compound interest calculation itself.

    savings = 100
    for i in range (15):
        print (savings) # try to write output
        savings = savings * 1.05
    print (savings)


    The results are printed below.
    100
    105.0
    110.25
    115.7625
    121.55062500000001
    127.62815625000002
    134.00956406250003
    140.71004226562505
    147.74554437890632
    155.13282159785163
    162.8894626777442
    171.03393581163144
    179.58563260221302
    188.56491423232367
    197.99315994393987
    207.89281794113688