Skip to content

crwdns342183:0crwdne342183:0

crwdns360448:0crwdne360448:0

crwdns338145:0crwdne338145:0 | MakeCode, Python | crwdns255566:0crwdne255566:0, crwdns255570:0crwdne255570:0 | crwdns258504:0crwdne258504:0, crwdns258514:0crwdne258514:0, crwdns293294:0crwdne293294:0, crwdns293304:0crwdne293304:0

crwdns360368:0crwdne360368:0

crwdns360370:0crwdne360370:0

crwdns360372:0crwdne360372:0 crwdns360374:0crwdne360374:0 crwdns360376:0crwdne360376:0

crwdns360378:0crwdne360378:0

crwdns360384:0crwdne360384:0

crwdns360386:0crwdne360386:0

crwdns360388:0crwdne360388:0 crwdns360390:0crwdne360390:0

crwdns360392:0crwdne360392:0

  • crwdns360394:0crwdne360394:0 crwdns360396:0crwdne360396:0 crwdns360398:0crwdne360398:0
  • crwdns360400:0crwdne360400:0 crwdns360402:0crwdne360402:0
  • crwdns360404:0crwdne360404:0
  • crwdns360406:0crwdne360406:0 crwdns360408:0crwdne360408:0 crwdns360410:0crwdne360410:0
  • crwdns360412:0crwdne360412:0 crwdns360414:0crwdne360414:0 crwdns360416:0crwdne360416:0

crwdns360418:0crwdne360418:0

  • crwdns360420:0crwdne360420:0
  • crwdns360422:0crwdne360422:0
  • crwdns360424:0crwdne360424:0

crwdns360426:0crwdne360426:0

1from microbit import *
2import random
3
4# An error could appear if you press button B without pressing button A first.
5# If the variable ‘number’ has not been assigned.
6# To work around this, the value of 101 is assigned to the variable 'number' 
7# at the start of the program. When you press button B the program tests 
8# first to see if the value of ‘number’ is 101 - if it is, it shows a helpful message.
9
10number = 101
11
12while True:
13    if button_a.was_pressed():
14        number = random.randint(1, 100)
15        display.scroll(number)   
16    if button_b.was_pressed():
17        if number == 101:
18            display.scroll('no number chosen yet') 
19        elif number%2 == 0:
20            display.scroll('even')   
21        else:
22            display.scroll('odd') 

crwdns360428:0crwdne360428:0

  • crwdns360430:0crwdne360430:0
  • crwdns360432:0crwdne360432:0 crwdns360434:0crwdne360434:0 crwdns360436:0crwdne360436:0
  • crwdns360438:0crwdne360438:0