Hello,

> I have attached a copy of the code I've compiled so far.

Next time just post the code in here, I think that's the general
consensus around here. You should only attach it or use a pastebin if
it's really really long. Considering that usually the only valid
entries here are snippets of code you've isolated that do not work
(functions/methods...), code that gets posted here is usually not too
long.
Anyhow the graphics.py module is unbeknownst to me, but I presume
you're reffering to this one:
http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/graphics.html

What you're doing wrong is your input:
    principal = eval(input.getText())
    apr = eval(input2.getText())
Those commands are in order, however their position in programing is
not. Let's examine:
1. you draw your input screen and define standard inputs for boxes
2. during the drawing session you read in values for which you have
provided input boxes
3. you plot the values in a bar graph.
When this runs it goes like this:
1. you draw your input screen, set values in input boxes to 0.0 and 0.0
2. apr and principal get set to 0.0 and 0.0
3. plot graph and values

and of course every single bar gets ploted to 0, because those are the
values of your inputs. If there is no principal to add apr to there is
no net result. You should make it so that apr and principal get set
AFTER the initial screen drawing session but BEFORE plotting,
therefore after the mouse-click.
You're also making a mistake of not actually changing any values as
the year progresses:
            bar = Rectangle(Point(year, 0), Point(year+1, principal))
every bar will have the same height, that of the inputed principal value.

I don't know if it's encouraged here or not, to give straight away
answers, but here it goes anyway because I think znx is missing couple
of other things as well:
To sort out the wrong inputing move the eval() lines after the
win.getMouse() statement, preferably right before the for loop
statement. Your principal grows each year by the value of apr, so if
you have a 1000$ in the bank and the bank awards you with 500$ each
year (good luck with that) then by the end of the first year you
should have 1500$, by the end of the 2nd year 2000$ because the 1st
year becomes the principal for the 2nd year, by 3rd year it's 2500$
and so on....
To introduce the changing values you have to have a new variable to
store the increased original value, let's call that variable
"newvalue". Then you have to increase the value of the new variable
every complete step of the for loop. Each full circle of for loop
should see at least 1 newvalue = newvalue +apr (or newvalue+=apr in
short).

This solution removes the need for the # Draw bar for initial
principal set of orders so delete it:
    # read values in input boxes AFTER the button click
    principal = eval(input.getText())
    apr = eval(input2.getText())

    #create new value that you'll increase every year by apr
    newvalue = principal+apr #this is the net money by the end of 1st year

    # Draw a bar for each subsequent year
    for year in range(0, 11): #by going from 0 you don't have to
specifically plot 1st year
        bar = Rectangle(Point(year, 0), Point(year+1, newvalue))
        newvalue = newvalue+apr
        bar.setFill("green")
        bar.setWidth(2) #I don't know if this serves any purpose
because the width of your bar is defined with year to year+1 values.
Maybe it's the line width?
        bar.draw(win)

and that should do it. For a test run use print statement to check
that the for loop does what you want it too and use simple numbers as
principal=1000 and apr=500, you should get 1500, 2000, 2500......
(This looked a lot like a fixed interest rate assignment so I guess
that's the purpose, note that because of the set scale of the graph
you should always use larger numbers because smaller ones will not be
visible).

You can make your y axis change by the value of input if you:
1. read input after button click but before setting the scale
2. set scale from 0 to maximal achievable value + some aditional
"height" that you can see the entire graph (p.s. maximal achievable
value is principal+final_year*apr, so in your case,
principal+11*apr+500 [for spacing])
3. plot the rest

Good luck,
Dino
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to