MicroPython メモ 4 / if, elif, else

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.34-35
 
「コロン」「インデント」「elif の綴り」に気をつけさえすれば使い方は他の言語と同じ。

from microbit import *

while True:
    if button_a.was_pressed():
        display.scroll("A pressed")


 

from microbit import *

while True:
    if button_a.was_pressed():
        display.scroll("A!")
    elif button_b.was_pressed():
        display.scroll("B")
    else:
        display.scroll("Push!")