Microbit
Beginner
50 mins
Teacher/Student led
+170 XP

Variables, Input and Output in Python

Students build a higher-or-lower game in Python on the micro:bit editor, learning to declare, assign and update variables and to handle button input and screen output. They predict, run, investigate and debug their code step by step.

Teacher Class Feed

Load previous activity

    1 - Start: What We're Building ~5 mins

    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.

    2 - Predict Before You Run ~10 mins

    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.

    3 - Introduction ~3 mins

    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.

    4 - What Are Variables? ~2 mins

    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.14

    In this example, we have created four variables:

    • 'age' stores an integer
    • 'message' stores some text
    • 'isOpen' stores a true/false value
    • 'productPrice' stores a decimal number

    5 - Declaring and Assigning Variables ~2 mins

    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 = 10

    This creates a variable named 'my_variable' and assigns it the value 10.

    123learn · Online learning platform

    Unlock the full learning experience

    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.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2025. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more