Mar-10-2020, 10:46 AM
(This post was last modified: Mar-10-2020, 11:03 AM by SemiBeginnerPY.)
(Mar-10-2020, 04:20 AM)deanhystad Wrote: To draw 5 stick figure you could do something like this:
def main(): """Draw stick figures, side by side""" turtle.pensize(4) turtle.title("Stick Figures") turtle.up() turtle.back(200) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) turtle.done()This draws five stick figures. What instructions were repeated five times? Those instructions are what you want to execute in the loop, nothing more and nothing less.
Then next thing is figure out how to write a loop. You have a loop in you code that would draw an additional two stick figures if you hadn't already called turtle.done(). How could you make that loop execute 5 times?
the code i have, i should have put that the for loop in myc ode doesnt work as i was trying to test it myself.
def main(): """Draw the two stick figures, side by side""" init() draw_stick_figure() # left stick figure turtle.forward(100) draw_stick_figure() # right stick figure turtle.hideturtle() turtle.done() for i in range(1): init() draw_stick_figure() # left stick figure turtle.forward(200) draw_stick_figure() # right stick figure turtle.hideturtle() turtle.done() main()the forloop used here, doesnt work as i was testing it for myself before i asked for help.
so without the for loop my code would be:
def main(): """Draw the two stick figures, side by side""" init() draw_stick_figure() # left stick figure turtle.forward(100) draw_stick_figure() # right stick figure turtle.hideturtle() turtle.done() main()
(Mar-10-2020, 04:20 AM)deanhystad Wrote: To draw 5 stick figure you could do something like this:would the for loop go along the lines of:
def main(): """Draw stick figures, side by side""" turtle.pensize(4) turtle.title("Stick Figures") turtle.up() turtle.back(200) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) draw_stick_figure() turtle.forward(100) turtle.done()This draws five stick figures. What instructions were repeated five times? Those instructions are what you want to execute in the loop, nothing more and nothing less.
Then next thing is figure out how to write a loop. You have a loop in you code that would draw an additional two stick figures if you hadn't already called turtle.done(). How could you make that loop execute 5 times?
for i in range(5) draw_stick_figure() turtle.forward(100) turtle.done()
seems like i have corrected my problem
the solution:
def main(): """Draw the two stick figures, side by side""" turtle.pensize(4) turtle.title("Stick Figures") turtle.up() turtle.back(200) for i in range(5): draw_stick_figure() turtle.forward(100) main()Thank you for helping