Computer 2

Thursday, March 5, 2026

Python Lists Quiz and Introduction to the BBC Micro:bit

Agenda

  1. Take the Python Lists Quiz.
  2. Learn about the BBC Micro:bit and how to program it with Python in Thonny.
  3. Write your first Micro:bit programs: a scrolling message and an image slideshow. These are just for practice — you don't need to turn them in.

Python Lists Quiz

When it is time to take the quiz, the Quiz link will be written on the board. Enter the quiz code in the text field below and click "Submit".

Introduction to the BBC Micro:bit

A pocket-sized computer you can program with Python.

What Is the BBC Micro:bit?

The BBC Micro:bit is a small programmable computer designed for learning to code. It has a lot packed into a tiny board:

You will write Python code on your computer, then send it to the Micro:bit over USB using Thonny.

Setting Up Thonny for the Micro:bit

  1. Plug the Micro:bit into your computer with a USB cable.
  2. Open Thonny.
  3. In the bottom-right corner of the Thonny window, click the interpreter selector (it may say something like "Python 3.x").
  4. Select MicroPython (BBC micro:bit) from the list.
  5. If prompted to install or update MicroPython on the device, click Install and wait for it to finish.

Once connected, you will see the Shell panel at the bottom of Thonny. You can type Python commands there directly, or write a program in the editor and click Run to send it to the Micro:bit.

Important: Every Micro:bit program must begin with from microbit import *. This loads all of the Micro:bit's built-in features so your code can use them.

Scrolling Messages

The simplest thing you can do with the Micro:bit display is scroll a message across the LEDs. Use display.scroll() and pass it a string.

from microbit import *

display.scroll("Hello, World!")

When you run this, the message scrolls across the 5×5 LED display one character at a time. The program ends when the full message has scrolled past.

Scrolling a number

You can scroll numbers too — just convert them to a string first with str():

from microbit import *

score = 42
display.scroll("Score: " + str(score))

Looping forever

Use a while True: loop to keep repeating. The sleep() function pauses for a number of milliseconds (1000 ms = 1 second).

from microbit import *

while True:
    display.scroll("Go Hawks!")
    sleep(500)   # wait half a second before repeating

Built-in Images

Instead of scrolling text, you can display one of the Micro:bit's many built-in images using display.show().

from microbit import *

display.show(Image.HEART)

Available Images

Here are some of the built-in images you can use:

Image constant What it looks like
Image.HEART Heart
Image.HAPPY Happy face
Image.SAD Sad face
Image.SMILE Smiling face
Image.ANGRY Angry face
Image.SURPRISED Surprised face
Image.ASLEEP Sleeping face
Image.YES Check mark
Image.NO X mark
Image.SKULL Skull
Image.UMBRELLA Umbrella
Image.SNAKE Snake
Image.RABBIT Rabbit
Image.COW Cow
Image.DUCK Duck
Image.HOUSE House
Image.GHOST Ghost
Image.SWORD Sword
Image.DIAMOND Diamond
Image.TARGET Target / bullseye

Image Slideshow

Use a list and a for loop to cycle through several images. This is a great way to practice both lists and Micro:bit programming at the same time!

from microbit import *

# A list of images to display
images = [Image.HEART, Image.HAPPY, Image.SMILE, Image.SURPRISED, Image.SAD]

while True:
    for image in images:
        display.show(image)
        sleep(800)   # show each image for 0.8 seconds

Notice how this uses a Python list — exactly like the ones from the quiz — to store the images, and a for loop to step through them one by one.

Clearing the Display

To turn off all the LEDs, call display.clear():

from microbit import *

display.show(Image.HEART)
sleep(2000)
display.clear()   # turn off all LEDs