Back

Drawing shapes using functions and the turtle module - practical work 1

Q1. Get this code working:

import turtle

turtle.bgcolor("orange")

def square(length):
     turtle.forward(length)
     turtle.right(90)
     turtle.forward(length)
     turtle.right(90)
     turtle.forward(length)
     turtle.right(90)
     turtle.forward(length)
     turtle.right(90)

#draw the first square ....
square(50)

#draw the second square ....
turtle.penup()
turtle.goto(20,20)
turtle.pendown()
square(60)

#draw the third square ....
turtle.penup()
turtle.goto(40,40)
turtle.pendown()
square(70)

#draw the fourth square ....
turtle.penup()
turtle.goto(60,60)
turtle.pendown()
square(80)

#draw the fifth square ....
turtle.penup()
turtle.goto(80,80)
turtle.pendown()
square(90)

Q2. Draw two more squares, following the same pattern.
Q3. Change some of the vlaues in the program and see what happens.
Q4. Add some squares going in different directions hint: use negative coordinates e.g. turtle.goto(-20,-20)

turtle.goto(20,-20) and
turtle.goto(-20, 20)

Back