Recap: Last time, what is a variable and what can it hold? Today we're coding in Python and building a higher-or-lower game on the micro:bit, one step at a time on your devices. We'll predict what the code will do, build it, run it and fix anything that breaks. First, look at what we're about to build — don't run anything yet.
Open with the recap question — what is a variable and what kinds of value can it hold? Set the scene: we're building a higher-or-lower game in Python, predicting and fixing as we go. Have the micro:bit Python editor open on the board but don't show the code yet. Cue students to pair up and log in.
Before anyone runs a single line: look at what we're about to build and commit to a prediction. When the program runs, what do you think will show on the micro:bit screen first? What should happen when you press a button? Tell your partner your prediction now — we'll come back to it later.
This is the PRIMM predict beat. Ask students to commit out loud to a partner: what shows on the screen first, what happens on a button press? Collect two or three predictions and write them on the board so you can revisit them at the make-sense step. No typing yet — the point is the commitment before running.
In this lesson, you will learn about variables in Python, how to declare and assign them, their types, and good naming conventions. You will also create a higher or lower game using the Microbits Python editor.
Frame what's ahead: variables first, then the game build. Reassure students that 'declare', 'assign' and 'type' will be explained as we go. Key question: why might storing a value in a variable be useful in a game? Keep it brief — the real work starts with the next steps.
Variables are used to store values in a program. They have a name and can store different types of data such as numbers, text, and more. In Python, you don't need to specify the type of data a variable will store, as it automatically detects the type based on the value you assign to it.
Let's take a look at some examples of declaring and assigning variables of different types:
age = 42
message = "Hello, World!"
isOpen = True
productPrice = 3.14In this example, we have created four variables:
Model the idea on the board that a variable is a name pointing at a value. Ask: how does Python know whether something is a number or text? Watch for students writing the name on the wrong side of the equals sign. Support: have students read each line aloud as 'store this value in this name'.
To declare and assign a variable in Python, you simply write the variable name followed by an equal sign and the value you want to store. For example:
my_variable = 10This creates a variable named 'my_variable' and assigns it the value 10.
Model one declaration on the board so students see the name-equals-value pattern before typing. Key question: what is on the left of the equals, and what is on the right? Common slip: a stray space or capital letter changing the variable name. Differentiation: let supported students copy the pattern, then change just the value.
You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.