Calculating compound interest.
Code: "finance2.py". Programming language: Python DMelt Version 1. Last modified: 07/05/2015. License: Pro
https://datamelt.org/code/cache/finance2_4933.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


from jhplot import *
 
principal=10000.0 # starting principal (initial investment)
rate=0.05         # percentage of interest rate
maxyear=50        # maximal years

c1=HPlot()
c1.visible(); c1.setAutoRange()
c1.setMarginLeft(100)
p1=P1D("Value $$")
p1.setDrawLine(1)   # show as connected lines
for year in range( 1, 21 ):
   amount = principal*(1.0+rate)**year
   print "%4d%21.2f" % ( year, amount )
   p1.add(year,amount)
c1.setNameX("year")
c1.setNameY("balance $$") 
c1.draw(p1)

Ads help maintain this website.