in Class Code 4-16-15
Compound Interest Graph:
from graphics import *
def main():
print("This program plots the growth of a 10-year investment.")
principal = eval(input("Enter the initial principal: "))
apr = eval(input("Enter the annualized interest rate: "))
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)
height = principal * 0.02
bar = Rectangle(Point(40,230), Point(65, 230-height))
bar.setFill("green")
bar.setWidth(2)
bar.draw(win)
for year in range(1,11):
principal = principal * (1 + apr)
x11 = year * 25 + 40
height = principal * 0.02
bar = Rectangle(Point(x11, 230), Point(x11 + 25, 230 - height))
bar.setFill("green")
bar.setWidth(2)
bar.draw(win)
input("Press <Enter> to quit")
win.close()
main()
Circle Chase:
from graphics import *
def main():
win = GraphWin("Click Me!")
center = Point(100, 100)
circ = Circle(center,30)
circ.setFill('red')
circ.draw(win)
colBoxX = circ.getP1()
colBoxY = circ.getP2()
for i in range(10):
colBoxX = circ.getP1()
colBoxY = circ.getP2()
p = win.getMouse()
clickX = p.getX()
clickY = p.getY()
if colBoxY.getX() > 200 and colBoxY.getY() > 200:
circ.move(100,100)
circ.draw(win)
else:
if clickX > colBoxX.getX() and clickX < colBoxY.getX():
if clickY > colBoxX.getY() and clickY < colBoxY.getY():
circ.move(20,20)
main()