# futval_graph_1.py # # Plots an investment 10 years into the future, # using Zelle's graphics package. # # Based closely on code from Zelle's Python book. # # Jim M, Sep 2010 # from graphics import * def main(): print "This program plots the growth of a 10 year investment." principal = input("Enter the initial principal (e.g. 1000) : ") apr = input("Enter the annualized interest rate (e.g. 0.25) : ") # Create the window, and put some text labels along the axis. window = GraphWin("Investment Growth Chart", 480, 360) window.setBackground("white") window.setCoords(-1.75, -200, 11.5, 10400) Text(Point(-1, 0), ' 0.0K').draw(window) Text(Point(-1, 2500), ' 2.5K').draw(window) Text(Point(-1, 5000), ' 5.0K').draw(window) Text(Point(-1, 7500), ' 7.5k').draw(window) Text(Point(-1, 10000), '10.0K').draw(window) # Draw a bar for the original principal. bar = Rectangle(Point(0, 0), Point(1, principal)) bar.setFill("green") bar.setWidth(2) bar.draw(window) # And then do the same for each of 10 years. for year in range(1, 11): principal = principal * (1 + apr) bar = Rectangle(Point(year, 0), Point(year+1, principal)) bar.setFill("green") bar.setWidth(2) bar.draw(window) raw_input("Press to quit.") window.close() main()