def balance (p, apr, mo):
mpr = 0.01*apr/12.0
for month in range(int(mo)):
p= p+p*mpr
return p
for i in range(1,13):
print balance(1000,10,i)
Strictly this mpr is not correct (monthly compounding is a simplification that was justified in times before slide rules); the monthly rate should be the 12th root of the annual rate; see continous compounding https://en.wikipedia.org/wiki/Compound_interest
def balance2 (p, apr, mo):
mpr = ((1+apr/100.0)**(1/12.0)-1)
for month in range(int(mo)):
p= p+p*mpr
return p
print
for i in range(1,13):
print balance2(1000,10,i)
output:
1008.33333333
1016.73611111
1025.20891204
1033.75231964
1042.3669223
1051.05331332
1059.81209093
1068.64385836
1077.54922384
1086.52880071
1095.58320738
1104.71306744
1007.97414043
1016.01186777
1024.11368908
1032.28011546
1040.51166206
1048.80884817
1057.17219721
1065.60223677
1074.09949864
1082.66451888
1091.29783779
1100.0