Mar-09-2020, 11:41 PM
Hi everyone, im still a beginner for PY.
recently i have been trying to create stickman in Python using turtle. i dont want to use multiple methods to create all the stickman. so ive thought of adding a loop to my code. ill put the code below for you guys to look at and help me identify how i can solve this problem.
my code for the stickman drawing:
Any help would be appreciated.
**before anyone asks i have read and researched about using loops but i cannot find a way to input the for loop into my code for this to work.
i forgot to add my code before this and what i am creating:
recently i have been trying to create stickman in Python using turtle. i dont want to use multiple methods to create all the stickman. so ive thought of adding a loop to my code. ill put the code below for you guys to look at and help me identify how i can solve this problem.
my code for the stickman drawing:
def init(): turtle.pensize(4) turtle.title("Stick Figures") turtle.up() def draw_torso(): turtle.color('blue') turtle.right(90) turtle.down() turtle.forward(100) turtle.up() turtle.back(100) turtle.left(90) def draw_legs(): turtle.color('green') turtle.right(90) turtle.forward(100) turtle.right(45) turtle.down() turtle.forward(30) turtle.back(30) turtle.left(90) turtle.forward(30) turtle.back(30) turtle.right(45) turtle.up() turtle.back(100) turtle.left(90) def draw_arms(): """Draw the arms""" turtle.color('yellow') turtle.right(90) turtle.forward(30) turtle.left(90) turtle.down() turtle.forward(30) turtle.back(30) turtle.left(180) turtle.forward(30) turtle.back(30) turtle.left(90) turtle.up() turtle.back(30) turtle.left(90) def draw_head(): """Draw the head""" turtle.color('purple') turtle.down() turtle.circle(25) turtle.up() def draw_stick_figure(): """Draw a complete single stick figure""" draw_torso() # task 1 - draw the torso draw_legs() # task 2 - draw the legs draw_arms() # task 3 - draw the arms draw_head() # task 4 - draw the head 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 code above depicts how ive made two stickman side by side, however i want to change that now by adding a for loop where the turtle will keep on creating stickman by using my loop. i want to create atleast 5 stickman side by side.
Any help would be appreciated.
**before anyone asks i have read and researched about using loops but i cannot find a way to input the for loop into my code for this to work.
i forgot to add my code before this and what i am creating:
import turtle import time t = turtle.Turtle() scale = 25 #Task 2.1 def initials(): ## Letter A t.penup() t.setx(0) t.sety(0) t.down() # Point upwards to begin t.left ( t.heading ( ) + 90 ) t.right ( 20 ) t.forward ( 10 * scale ) t.right ( 70 ) t.forward ( 1 * scale ) t.right ( 70 ) t.forward ( 10 * scale ) t.backward ( 5 * scale ) t.right ( 90 + 20 ) t.forward ( 5 * scale ) t.up ( ) t.backward ( 5 * scale ) t.left ( 110 ) t.forward ( 5 * scale ) t.left ( 70 ) t.forward ( 1 * scale ) t.setx(200) t.sety(10) t.pendown() ## Ltter W t.right(90) t.forward(50) t.left(150) t.forward(40) t.right(120) t.forward(40) t.left(150) t.forward(50) t.penup() t.right(90) t.forward(50) initials() t.hideturtle() t.clear()the code above makes my initials as you can see i have commented on each line so this should make more sense for anyone wondering what/why i am coding this. the code above is inserted before the stickman code.