Microbit
Beginner
40 mins
Teacher/Student led
+130 XP

Studio: Rock, Paper, Scissors in Python

Students build a Rock-Paper-Scissors game in the micro:bit Python editor using lists, randomness, button input and conditionals, tracing a round by hand before they run and debug.

Teacher Class Feed

Load previous activity

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

    Illustration for Start: what we're buildingToday you are coding in Python on the micro:bit editor. You will build a Rock-Paper-Scissors game step by step: predict what a round should do, then build, run and fix.

    You can already use simple Python and make the micro:bit respond. By the end you will have a full game where you press buttons for rock, paper or scissors, the micro:bit picks at random, and the display shows who won.

    Before you run anything, think: if you choose rock and the micro:bit chooses scissors, who should win, and what should appear on the screen?

    2 - Introduction to the Game ~3 mins

    In this lesson you'll create a Rock-Paper-Scissors game using your Micro:bit and the Micro:bit will act as your opponent. You'll use the buttons to make your choice, generate a random choice for the computer using the random module, compare the outcomes with if-else statements, and display the results on the LED screen with messages like 'You win!'. We'll store the possible choices in a list to practise list handling.

    By the end of this lesson, you'll have a fully interactive game. Open the Micro:bit Python editor at python.microbit.org and start a new project.

    Remember to test your code frequently by running it in the simulator. The game will respond to button presses on the virtual Micro:bit.

    3 - Import Modules ~2 mins

    In this step, we'll import the necessary modules. We need the microbit module for hardware access and the random module to generate the computer's choice.

    Start by adding the following complete code to your editor:

    from microbit import *
    import random
    This imports everything from microbit and the random module. Run the code; nothing will happen yet, but it should run without errors.
    If you see any import errors, check your spelling and ensure you're using the online editor.

    4 - Define Choices List ~3 mins

    Next, we'll create a list to store the possible choices: rock, paper, and scissors. Lists are great for holding multiple related items, and we'll use this to select the computer's choice randomly.

    Update your code to the following complete version:

    from microbit import *
    import random
    
    choices = ["rock", "paper", "scissors"]
    display.scroll("Ready")
    Avoid copy-pasting the code. Type each line to master the code’s logic and structure.
    Run the code. You should see 'Ready' scroll on the display. This confirms the list is set up. The list 'choices' now holds three string items. We'll use it later for random selection.
    Try adding display.scroll(choices[0]) after the list to show 'rock'. This practises accessing list elements.
    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 - 2026. 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