from microbit import *
from random import randint
shapes = "TIJLOSZTIJLOSZTIJLOSZTIJLOSZTIJLOSZT "
display.show("-")
while True:
if button_a.was_pressed():
display.show(" ")
sleep(100)
ln = len(shapes)
if ln == 1:
break
r = randint(0,ln-2)
display.show(shapes[r])
if r == 0:
shapes = shapes[1:]
else:
shapes = shapes[0:r] + shapes[r+1:]
display.show("=")
由於 MicroPython 不是一般 Python,它只提供精簡版的函數庫,所以不足的功能要自己寫。上面的程式每按一次 A 鍵,隨機抽一個拼塊,因此程式將 36 個拼塊依序排列一字串,亂數隨機抽一個,被抽到的字塊拿掉,未被抽走的字塊再合併成一字串,再隨機抽籤,直到抽完為止。
新春好消息:LEGO Educaiotn Computer Science AI Kit 電子零件規格
-
有消息指出,LEGO Educaiotn Computer Science AI Kit 的馬達表現比SPIKE
Prime的馬達弱,那是一定的,因為內建電池比較不足啊!
大家先參考參考,新春愉快!
2 週前

沒有留言:
張貼留言