- #1
gravenewworld
- 1,132
- 26
Homework Statement
To modify a future value program so that a user inputs the data w/ a GUI
Homework Equations
principal = principal * (1+apr)
The Attempt at a Solution
Anyone familiar w/ python coding? I'm a beginner. I'm absolutely stuck on this problem, I seem to have gotten everything, except I simply can not figure out how to write the program so that it can take the values the user inputs for principal and apr in the entry boxes and uses those values to run the equations for future value over 10 years. Been stuck on this for hours. Here's my code:
from graphics import *
def main():
# Get principal and interest rate in GUI
win = GraphWin("Future value calculator", 300, 300)
win.setCoords(0, 0, 300, 300)
Text(Point(75, 200), " Enter principal: "). draw(win)
Text(Point (75, 150), "Enter interest rate: ").draw(win)
input = Entry(Point(200, 200), 10).draw(win)
input = Entry(Point(200, 150), 10).draw(win)
button = Text(Point(150, 20), "Calculate")
button.draw(win)
Rectangle(Point(100, 10), Point(200, 30)).draw(win)
#mouse click
win.getMouse()
# 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), ' 7.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)
input("Press <Enter> to quit.")
win.close()
main()
I'm a beginner and have only been coding for 1.5 weeks, so I need simple explanations with no fancy expert coding tricks.