Use a loop to repeat. Inside it, call polygon, then turn a little.
Another hint
To go round once in total, each turn is 360 divided by the number of copies.
Write pattern(sides, copies) and run it.
Run your program. This ticks when your code does all of the above.
MakeBuild something new using what you have learned. Expect a few tries; that is normal.
Keep it as a button
You have unlocked Save selection to My tools. Open Reference, put the cursor inside one of your functions, and click it. It appears under My tools, ready to copy into any program. A saved tool is the first layer of abstraction: you can use the idea again without rewriting it.
Try it yourselfYour edits are saved in this browser.
ModifyChange the code on purpose and check the result.
Rearrange a floor plan
A floor plan is room(width, depth) called many times. Run it. Move the kitchen, add a bathroom, then change scale and see the whole plan resize.
Try it yourselfYour edits are saved in this browser.
Lesson done. You've finished every step you need.
Now you can
Write a function with parameters and call it with different values.
Explain the difference between a parameter (the name in the def) and an argument (the value in the call).
Students give a function inputs (parameters), so one function can draw many sizes and shapes, then build a pattern by calling one function from another. About 55 minutes.
I can write a function with parameters and call it with different values.
I can explain the difference between a parameter (the name in the def) and an argument (the value in the call).
I can call one function from inside another.
Before class
Run the three nested squares and try adding a colour parameter to polygon. Two words to have straight: a parameter is the name in the def (size), an argument is the value you pass when calling (50). The argument fills the parameter, in order.
Running the lesson
Predict: ask why the three squares share a corner. They all start where the turtle is, facing the same way; only size changes.
Run: students try their own sizes. Ask what would happen with square(-50).
Investigate: arguments go to parameters in order. polygon(6, 80) fills sides with 6 and size with 80. Swapping them gives an 80-sided shape.
Modify: adding a colour parameter means changing the def and every call. That is the 'contract' between a function and its callers.
Make: pattern calls polygon in a loop and turns a little each time. Set speed(0) so it draws quickly.
My tools: students save a function to My tools in the Reference panel. It is a copy they can paste into later programs.
The hard part (on purpose)
Arguments fill parameters in order. Read the call and the def aloud side by side and match each value to its name.
When students get stuck
A TypeError: polygon() missing 1 required positional argument. Ask: How many parameters does the def have, and how many values does this call pass? Fix: Every call must pass one value for each parameter, in the same order.
The shape has far too many sides or does not close. Ask: Which value went into sides, and which into size? Fix: Arguments match parameters by position. polygon(6, 80), not polygon(80, 6).
The pattern draws one shape on top of itself. Ask: Does the turtle turn between the copies? Fix: Add right(360 / copies) inside the loop, after drawing each polygon.
Stretch and support
Stretch: Add a third parameter to pattern for the size, and draw a gallery of three different patterns side by side.
Support: Give students a table of calls (square(50), square(100)) and ask them to sketch what each draws before running.
Where it leads
Next lesson functions give answers back with return. Parameters are how every app passes information around. Class ideas: a pattern gallery where each student chooses sides and copies; compare function designs and talk about what makes one easy to reuse.
What each step is for
Investigate: A parameter lets one function make many results: each call passes arguments in order, and the function calculates from them.
Modify: Extending a function means changing its definition and every call; it shows why parameters are a contract between the def and its callers.
Mix it up: A parameter can be used in a calculation, like any name.