MicroPython亂數的應用
from microbit import *
import random
while True:
display.show(random.randint(0, 9))
sleep(1000)from microbit import *
import random
guess = 5
while True:
if button_a.is_pressed() and button_b.is_pressed():
break;
if button_a.was_pressed():
guess += 1
if guess > 9:
guess = 9
elif button_b.was_pressed():
guess -= 1
if guess < 0:
guess = 0
display.show(guess)Last updated