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).
In this project, your team will make four turtles draw their shapes simultaneously. They will take turns drawing each side of their shapes.
Your team will also add some random
features to make the final drawing more
eye-catching.
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:
Each group needs their own copy of the code.
11.9.4. Activity¶
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.
Once you join a group, decide who will be the driver, and who will be the navigators.
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.
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.
Note
Your team will only finish on time if everyone does their job.
Everyone needs to practice, so let everyone contribute.
You learn to code by coding, not watching.
Tasks for each group:
Group 1 codes a function to randomly assign a shape to a turtle (arrow, circle, classic, square, triangle, turtle).
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).
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.
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.
Tip
Each function requires a parameter for a turtle object, and each function call must include a turtle as an argument.
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.
For now, there is no need to include a
return
statement in any of the functions.Communicate with your team about the name you give your function.
Your teacher will demonstrate a
place_turtles
function that starts different turtles at different spots on the screen.place_turtles
takes a list of turtles as one of the parameters, but it needs to be modified to make it better.Your teacher will walk through how to improve the code, and your team will use the final
place_turtles
code.
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.
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¶
Decide which functions can be saved in one or more separate modules.
Move those functions into the modules, then import them into the main program file.
Add a
main()
function to themain.py
file to hold any loose code. Also, add a function call to runmain()
.As you add the module(s) and
main()
, update your program as necessary to keep it running.