Typing for the micro:bit
Answers are for parents and teachers.
1
Write a MicroPython program that scrolls your first name and then shows a heart.
(any first name in quotation marks is correct) Program: 1 from microbit import * | 2 display.scroll("Sara") | 3 display.show(Image.HEART)
2
Find four mistakes in this program and write the correct version.
Python
1from microbit import * 2while True 3 if button_a.is_pressed 4 display.show(Image.no)
Line 2 needs a colon (while True:). Line 3 needs the brackets after is_pressed and a colon at the end (two mistakes). Line 4: Image.no must be in capitals, Image.NO. Correct version: Program (each → is 4 spaces of indentation): 1 from microbit import * | 2 while True: | 3 → if button_a.is_pressed(): | 4 → → display.show(Image.NO)
3
Write a program with two buttons: when A is pressed, scroll the word Up; when B is pressed, scroll the word Down.
Program (each → is 4 spaces of indentation): 1 from microbit import * | 2 while True: | 3 → if button_a.is_pressed(): | 4 → → display.scroll("Up") | 5 → if button_b.is_pressed(): | 6 → → display.scroll("Down")
4
Explain the difference between a syntax error and a logic error. Give one example of each for a micro:bit program.
A syntax error breaks the rules of the language, for example display.scrol("Hi"). A logic error follows the rules but does not do what the plan says, for example using button A when the plan says button B.
5
Predict what the program does when you press A briefly and release it.
Python
1from microbit import * 2while True: 3 if button_a.is_pressed(): 4 display.show(Image.YES) 5 sleep(2000) 6 display.show(Image.SQUARE_SMALL)
The board shows a tick for 2 seconds, and then it shows a small square, which stays on.