The following code draws a snake
import turtle
SIDE = 50
def triangle():
turtle.begin_fill()
for n in range(3):
turtle.forward(SIDE)
turtle.right(120)
turtle.end_fill()
def black_triangle():
turtle.fillcolor("black")
triangle()
def white_triangle():
turtle.fillcolor("white")
triangle()
def snake():
black_triangle()
turtle.forward(SIDE)
turtle.right(60)
white_triangle()
turtle.left(60)
snake()
Exercise
- Copy the code into your IDE and run it.
- Draw a snake 6 segments long
- Draw a red and green snake, 6 segments long.
- Draw pink and yellow snake, 6 segments long, but half the size of the previous snake.
- Use a for loop to simplify your code.
- Now draw a snake 10 segments long
Extension
Modify your code to draw a bracelet, as shown below.

Functions and Turtle Graphics
The following code is the start of a solution to the problem of drawing a chessboard. It uses functions to help make the code understandable
import turtle
# Declare this at the top. Put it in capitals to show it shouldn't be changed
SIDE = 50
def square():
turtle.begin_fill()
for n in range(4):
turtle.forward(SIDE)
turtle.right(90)
turtle.end_fill()
def black_square():
turtle.fillcolor("black")
square()
def white_square():
turtle.fillcolor("white")
square()
def move_one_square_right():
turtle.penup()
turtle.forward(SIDE)
turtle.pendown()
def move_one_square_down():
turtle.penup()
turtle.right(90)
turtle.forward(SIDE)
turtle.left(90)
turtle.pendown()
def white_black_line():
for n in range(4):
white_square()
move_one_square_right()
black_square()
move_one_square_right()
# Speed up the turtle
turtle.speed(0)
# Draw two lines of the chessboard
white_black_line()
turtle.home()
move_one_square_down()
move_one_square_down()
white_black_line()
Exercise
- Copy the code into your IDE. Watch out for indents!
- Run the code and see what it does.
- Add a function to draw a black_white() line
- Draw a chessboard using the functions provided
- Can you make you code more efficient, perhaps by using a for loop?
- What happens if you change the value of SIDE?
- Draw a 10×10 chessboard
Extension
The following function draws a hexagon:
def hexagon():
for n in range(6):
turtle.forward(50)
turtle.left(60)
- Use the function to draw a honeycomb pattern
- Can you make the honeycomb cover the whole screen?