Skip to content

Instantly share code, notes, and snippets.

@helenst helenst/adding.py
Last active Nov 13, 2015

Embed
What would you like to do?
Micropython adding game
import microbit
firstnum = microbit.random(4)
secondnum = microbit.random(5)
microbit.display.scroll('{} + {}'.format(firstnum, secondnum), 200)
def wait_for_pressed():
while 1:
buttona = microbit.button_a.is_pressed()
buttonb = microbit.button_b.is_pressed()
if buttona or buttonb:
break
while microbit.button_a.is_pressed() or microbit.button_b.is_pressed() :
pass
if buttona:
return 'a'
else:
return 'b'
def count():
answer = 0
while 1:
if wait_for_pressed() == 'a':
answer +=1
microbit.display.print(str(answer))
else:
break
if answer == firstnum + secondnum:
microbit.display.print(microbit.Image.HAPPY)
else:
microbit.display.print(microbit.Image.SAD)
return answer
count()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.