Learning Aim
To use selection so a program can choose between different outcomes.
Defined End Point
By the end of this lesson, you will be able to create a drawing that uses if, elif and else to respond to different choices.
Creative Code. Colourful Thinking.
Lesson 3
Use selection to make Turtle programs respond to choices.
Use these stages to move from reading code to creating your own version.
To use selection so a program can choose between different outcomes.
By the end of this lesson, you will be able to create a drawing that uses if, elif and else to respond to different choices.
What Happens Next?
if colour == "blue":
circle(50)
else:
square(50)
if mean?Stretch: Think of a real-life example of selection.
Predict which colour the turtle will use when the choice is set to flower.
Read the code first. Do not run it yet.
choice = "flower"
if choice == "flower":
pencolor("pink")
else:
pencolor("blue")
Which branch of the selection will run, and why?
Watch how selection chooses one drawing rule from more than one option.
Type this code into Mu Editor and run it.
from turtle import *
choice = "flower"
if choice == "flower":
pencolor("pink")
circle(50)
else:
pencolor("blue")
forward(100)
done()
Typing the code yourself helps build Python fluency and debugging skills.
Trace the condition and identify what happens when it is true or false.
Which line asks the question?
Which commands run when the condition is true?
Which commands run after else?
Change the choice value and test how the output changes.
Create a tiny choice-based drawing program.
Choose between two colours.
Choose between two shapes.
Create an interactive drawing choice with three outcomes.
Example code and output.
Use the example to connect the Python instructions with the visual result.
Example code
from turtle import *
choice = "flower"
if choice == "flower":
pencolor("pink")
circle(50)
else:
pencolor("blue")
forward(100)
done()
This WAGOLL uses selection to make a clear choice and produce the matching Turtle output.
Explain what you learned and identify the next improvement you would make.
Add another choice and create a third visual outcome.
How is selection similar to making a choice in Scratch?