Python Lists Quiz and Introduction to the BBC Micro:bit
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".
A pocket-sized computer you can program with Python.
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.
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.
from microbit import *. This loads all of the Micro:bit's
built-in features so your code can use them.
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.
You can scroll numbers too — just convert them to a string first with
str():
from microbit import * score = 42 display.scroll("Score: " + str(score))
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
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)
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 |
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.
To turn off all the LEDs, call display.clear():
from microbit import * display.show(Image.HEART) sleep(2000) display.clear() # turn off all LEDs