Search code examples
pythonbbc-microbit

Code formatting, basic temperature application


I am trying to create a basic code that will show the temperature on a BBC:microbit and then based on the temperature shown, after a button press different images will show on the screen. After a shake the micro:bit will show the current temperature and then if the value is less than 18 the following will occur. Is there something wrong with the way I have formatted my if statements?

while True:
    if accelerometer.was_gesture('shake'):
        display.scroll(temperature())

    if button_a.was_pressed() AND temperature < 18:
        display.set_pixel(0, 0, 9)
        display.set_pixel(0, 1, 9)
        display.set_pixel(1, 0, 9)
        display.set_pixel(1, 1, 9)
        display.set_pixel(1, 2, 9)
        display.set_pixel(1, 3, 9)
        display.set_pixel(1, 4, 9)
        display.set_pixel(2, 1, 9)
        display.set_pixel(2, 2, 9)
        display.set_pixel(2, 3, 9)
        display.set_pixel(2, 4, 9)
        display.set_pixel(3, 0, 9)
        display.set_pixel(3, 1, 9)
        display.set_pixel(3, 2, 9)
        display.set_pixel(3, 3, 9)
        display.set_pixel(3, 4, 9)
        display.set_pixel(4, 0, 9)
        display.set_pixel(4, 1, 9)

     else if button_b.was_pressed() AND temperature < 18:
        display.set_pixel(0, 0, 9)
        display.set_pixel(0, 1, 9)
        display.set_pixel(0, 2, 9)
        display.set_pixel(1, 0, 9)
        display.set_pixel(1, 1, 9)
        display.set_pixel(1, 2, 9)
        display.set_pixel(2, 0, 9)
        display.set_pixel(3, 0, 9)
        display.set_pixel(3, 1, 9)
        display.set_pixel(3, 2, 9)
        display.set_pixel(4, 0, 9)
        display.set_pixel(4, 1, 9)
        display.set_pixel(4, 2, 9)

Solution

  • Yes, else if in python is a single keyword elif