Each of the possible messages is held in a list. A list holds multiple values. In this example, the list has 9 values and each one of those 9 values is a string (of characters).
The square brackets and each item is separated by a comma. The list can also be arranged on a single line:
Was it Shaken?
.was_gesture(gesture) returns a True or False depending on whether
gesture was the most recently detected gesture.
.was_gesture(freefall) would return
True if the microbit was thrown into the air.
The API for the
accelerometer module lists other gestures that can be used.
Random Choice from List
.choice picks a random item from the
random requires the
random module to be imported. This is done at the beginning of the program:
A module (like
random) is a collection of pre-existing code you can reuse.
Share On Facebook Google Plus
Published: December 23, 2016 Updated: December 23, 2016
Make a funky 8-ball for the microbit. It shows a different message each time it’s shaken.