-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfutval_graph.py
45 lines (36 loc) · 1.28 KB
/
futval_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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 the left edge
win = GraphWin("Investment Growth Chart", 420, 340)
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("blue")
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()