# futval_graph2.py # Copied from Zelle textbook pp144-145 # Neal Nelson 2008.11.6 from graphics import * def main(): # Introduction print "This program plots the growth of a 10-year investment." # Get the principal and interest rate #principal = input("Enter the initial principal: ") principal = 1000 #apr = input("Enter the annualized interest rate: ") apr = 0.20 # Create a graphics window with labels on left edge win = GraphWin("Investment Growth Chart", 320, 240) win.setBackground("white") win.setCoords(-1.75, -200, 11.5, 10400) Text(Point(-1,0), ' 0.0K').draw(win) Text(Point(-1,2500), ' 2.5K').draw(win) Text(Point(-1,5000), ' 5.0K').draw(win) Text(Point(-1,7500), ' 07.5K').draw(win) Text(Point(-1,10000), ' 10.0K').draw(win) # Draw bar for initial principal bar = Rectangle(Point(0,0), Point(1,principal)) bar.setFill("green") bar.setWidth(2) bar.draw(win) # Draw a bar for each subsequent year 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(win) # Hold window open #raw_input("Press to quit.") #win.close() # A better click-to-close technique text = Text(Point(xmax/2, 10000), 'Click to close') text.draw(win) win.getMouse() win.close() main()