Rock Paper Scissors

We are all familiar with the game Rock Paper Scissors. Let's take a look at how we can code our micro:bits to play

What You Will Learn

  • How to create and use a variable.
  • How to use the micro:bit on shake function.
  • How to display images/shapes on the LED matrix.
  • How to use conditional if/else statements.
  • How to use comparison operators.
  • How to randomise choices.

What You Will Need

  • 1 x micro:bit
  • 1 x micro USB cable
  • 1 x battery pack for the micro:bit (optional)

Coding

What is a variable

Think of a variable as a box that stores information that can be used throughout our program. We give variables a descriptive name so we and others can understand what is going on within our program.

  1. Within your favourite browser (we recommend Google Chrome) go to python.microbit.org and press enter. This will load the MicroPython coding editor.
  2. Delete the text on lines 6-8.
  3. Click on line 3 and type import random.
  4. Click on line 6 and type the following code:
    Code so far

Completed code:

Completed Code

We have now finished coding rock paper scissors the next step is to download our code to the miro:bit.

Downloading the Code

  1. Take the micro USB cable and connect the micro:bit to the computer.
  2. Click on Connect.
  3. Click on your micro:bit and click connect.
  4. Click Download.

You have now successfully coded a micro:bit to play raock paper scissors.

Find a partner and start playing.