Program the micro:bit to give randomly a image of rock, papers or scissors when you press a button.
Help: how to create a image.
Each LED pixel on the physical display can be set to one of ten values. If a pixel is set to 0
(zero) then it’s off. It literally has zero brightness. However, if it is set to 9
then it is at its brightest level. The values 1
to 8
represent the brightness levels between off (0
) and full on (9
).
from microbit import *
boat = Image("05050:"
"05050:"
"05050:"
"99999:"
"09990")
display.show(boat)
You can rewrite it like this:
from microbit import *
boat = Image("05050:05050:05050:99999:09990")
display.show(boat)
Help: how to choice an image
draw = [papers, rock, scissors]
display.show(random.choice(draw))
The list (draw
) contains the three image names. The random.choice
method takes the draw
list as an argument and returns an item chosen at random (the draw of papers, rock or scissors).