Created
October 2, 2017 16:06
-
-
Save bmontana/a34628517b9bc134e3a1672e18ade9f2 to your computer and use it in GitHub Desktop.
Future Value graph program from 4.6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# futval_graph.py | |
from graphics import * | |
def main(): | |
# Introduction | |
print("This program plots the growth of a 10-year investment.") | |
# Get principal and interest rate | |
principal = float(input("Enter the initial principal: ")) | |
apr = float(input("Enter the annualized interest rate: ")) | |
# Create a graphics window with labels on left edge | |
win = GraphWin("Investment Growth Chart", 320, 240) | |
win.setBackground("white") | |
Text(Point(20, 230), ' 0.0K').draw(win) | |
Text(Point(20, 180), ' 2.5K').draw(win) | |
Text(Point(20, 130), ' 5.0K').draw(win) | |
Text(Point(20, 80), ' 7.5K').draw(win) | |
Text(Point(20, 30), '10.0K').draw(win) | |
# Draw bar for initial principal | |
height = principal * 0.02 | |
bar = Rectangle(Point(40, 230), Point(65, 230-height)) | |
bar.setFill("green") | |
bar.setWidth(2) | |
bar.draw(win) | |
# Draw bars for successive years | |
for year in range(1,11): | |
# calculate value for the next year | |
principal = principal * (1 + apr) | |
# draw bar for this value | |
xll = year * 25 + 40 | |
height = principal * 0.02 | |
bar = Rectangle(Point(xll, 230), Point(xll+25, 230-height)) | |
bar.setFill("green") | |
bar.setWidth(2) | |
bar.draw(win) | |
input("Press <Enter> to quit") | |
win.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment