11.9. Project: Collaborative Turtles Activity

11.9.1. Introduction

Functions and modules allow programmers to work on separate sections of code and then combine them together to create a finished project. In this activity, your class will split into teams, and each team will contain 4 groups.

Each group will create a function (or module) that performs a specific job. When all groups are ready, your team will combine all of the functions to assemble a working program.

11.9.2. Goal

If you define several turtle objects and call a draw_polygon function for each one, the turtles will draw their shapes sequentially (one after the other).

Animated gif showing 3 different turtles. Each turtle draws a complete triangle before the next one starts moving.

Drawing three triangles sequentially.

In this project, your team will make four turtles draw their shapes simultaneously. They will take turns drawing each side of their shapes.

Animated gif showing 3 different turtles. The turtles take turns as they draw one side of a polygon at a time.

Taking turns drawing the sides of a square.

Your team will also add some random features to make the final drawing more eye-catching.

Image showing 4 multi-colored pentagons with random turtle shapes and individual side colors.

Random side colors and turtle shapes.

11.9.3. Starter Code

If your teacher added you to a Trinket course, complete this project there.

If you are NOT enrolled in a Trinket course, use one of the following links to copy the starter code:

  1. Trinket project starter code
  2. repl.it project starter code

Each group needs their own copy of the code.

11.9.4. Activity

  1. Each team requires 4 groups, and each group should contain 2 - 4 coders (the ideal number in each group = 3). Your teacher will split the class into the teams, and you must decide which group to join.

  2. Once you join a group, decide who will be the driver, and who will be the navigators.

    1. The driver types code into the editor. However, the ideas for the code MUST come from the navigators. The driver is NOT the boss. They receive directions and enter code to make the ideas work.
    2. The navigators give ideas and instructions to the driver. However, they cannot type anything into the code editor themselves. The navigators are NOT the boss. They give suggestions for making the function work.


    Your team will only finish on time if everyone does their job.

    1. Everyone needs to practice, so let everyone contribute.
    2. You learn to code by coding, not watching.
  3. Tasks for each group:

    1. Group 1 codes a function to randomly assign a shape to a turtle (arrow, circle, classic, square, triangle, turtle).
    2. Group 2 codes a function to assign a random color to a turtle. Group members can use any colors they want, but there should be at least 7 choices in a list (Ex: red, orange, yellow, green, blue, indigo, violet).
    3. Group 3 codes a function to assign a speed to a turtle. Include a default speed value just in case the function call does not include that argument.
    4. Group 4 updates a function to make a list of turtles draw their shapes simultaneously instead of sequentially. The function is already in the starter code, but it does not quite work yet.


    1. Each function requires a parameter for a turtle object, and each function call must include a turtle as an argument.
    2. Each function might require other parameters as well. Consider the job your function must do, and decide in your group what other data will be needed.
    3. For now, there is no need to include a return statement in any of the functions.
    4. Communicate with your team about the name you give your function.
  4. Your teacher will demonstrate a place_turtles function that starts different turtles at different spots on the screen.

    1. place_turtles takes a list of turtles as one of the parameters, but it needs to be modified to make it better.
    2. Your teacher will walk through how to improve the code, and your team will use the final place_turtles code.
  5. Once each group in your team finishes their code, combine the separate functions into a single, shared file. Run the code to find and fix any bugs.

  6. Demonstrate your finished project to your teacher.

11.9.5. Submit Your Work

Save your final code, then follow the instructions given by your teacher to turn in your work.

11.9.6. Bonus Task

  1. Decide which functions can be saved in one or more separate modules.
  2. Move those functions into the modules, then import them into the main program file.
  3. Add a main() function to the main.py file to hold any loose code. Also, add a function call to run main().
  4. As you add the module(s) and main(), update your program as necessary to keep it running.
Animated gif showing the expected behavior of the final program. In this case, 5 different turtles take turns drawing the sides for 5 multi-colored octagons.