Last active
November 13, 2015 09:00
-
-
Save helenst/014e9650d270d4f940a6 to your computer and use it in GitHub Desktop.
Micropython adding game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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