在我的代码中,它应该是一个被操纵的魔术 8 球。按 A 应显示“是!”,按 B 应显示“否”。但每次都显示“是!” 无需按下任何按钮。
from microbit import *
import random
frameq = Image("00000:""00000:""00900:""00000:""00000")
framew = Image("00000:""09990:""09390:""09990:""00000")
framee = Image("99999:""93339:""93339:""93339:""99999")
framer = Image("33333:""33333:""33333:""33333:""33333")
framet = Image("22222:""22222:""22222:""22222:""22222")
framey = Image("11111:""11111:""11111:""11111:""11111")
frames = [frameq, framew, framee, framer, framet, framey]
answers = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes, definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it"
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful",
]
apress = False
bpress = False
while True:
if button_a.is_pressed:
bpress = False
apress = True
elif button_b.is_pressed:
apress = False
bpress = True
display.show("8")
if accelerometer.was_gesture("shake") and apress is True:
display.clear()
display.show(frames, loop=False, delay=250)
sleep(1000)
display.show("Yes!")
apress = False
elif accelerometer.was_gesture("shake") and bpress is True:
display.clear()
display.show(frames, loop=False, delay=250)
sleep(1000)
display.show("No.")
bpress = False
elif accelerometer.was_gesture("shake"):
display.clear()
display.show(frames, loop=False, delay=250)
sleep(1000)
display.scroll(random.choice(answers))
它没有显示错误消息,它只显示“是!” 每次我摇晃。顺便说一句,“是的!” 不在答案数组中,只有“是”,我总是看到!