5. Buttons and Selection Quiz

5.1. Question 1

Which button is located on the left-hand side of the micro:bit front panel?

Correct. Button A is on the left side, and Button B is on the right side.

Incorrect. Button B is positioned on the right side of the board.

Incorrect. There is no physical button named Button C on the micro:bit.

Incorrect. The reset button is located on the back of the micro:bit next to the USB plug.


5.2. Question 2

Which method should you call if you want to check whether Button A is actively being held down at this exact instant?

Correct. The .is_pressed() method checks the immediate, current state of the button.

Incorrect. This checks if the button was pressed at some point in the past since the last check.

Incorrect. There is no method named hold_down() in the microbit library.

Incorrect. The microbit library does not use a method named click() to detect inputs.


5.3. Question 3

What type of answer (data type) do you get back when you ask button_b.is_pressed()?

Incorrect. It returns a logical state, not a string of letters.

Incorrect. It does not return numbers.

Correct. It returns True if the button is pressed, or False if it is not.

Incorrect. It only returns true/false conditions, never decimals.


5.4. Question 4

If a micro:bit program checks button_a.is_pressed() while nobody is touching the board, what value does it return?

Incorrect. It will only return True if the button is physically pushed down.

Correct. Because the button is up and resting, the check evaluates to False.

Incorrect. It consistently provides a clear boolean True or False answer.

Incorrect. Button checks only return True or False.


5.5. Question 5

Look at the code statement below:

if button_a.is_pressed():
    display.show("A")

When will the letter “A” appear on the LED screen grid?

Incorrect. It relies strictly on checking the physical button state.

Incorrect. This line explicitly tests the button_a hardware object.

Correct. The conditional code block only runs if button_a.is_pressed() evaluates to True.

Incorrect. This is the standard syntax pattern used to check an input condition.


5.6. Question 6

If a program checks button_a.is_pressed() while the button is physically held down continuously, what value will it evaluate to on every check?

Correct. As long as the button remains actively pressed down, the method will consistently return True at that moment.

Incorrect. It only returns False if the button is not being pressed at the exact moment of evaluation.

Incorrect. The method returns a boolean value, not a None type object.

Incorrect. Button state methods return booleans (True/False), not integers.


5.7. Question 7

What happens if you run a loop that continuously calls button_a.was_pressed() while the button is held down continuously?

Incorrect. It only captures the initial transition event, not the ongoing state.

Correct. The method resets its history counter back to False immediately after being called, so it will not return True again until a new press occurs.

Incorrect. This is normal conditional logic and will not cause a hardware freeze.

Incorrect. It always returns a boolean value (True or False).


5.8. Question 8

Look at the following selection code block:

if button_a.is_pressed() or button_b.is_pressed():
    display.show(Image.HAPPY)
else:
    display.clear()

Under what condition will the micro:bit display the happy face image?

Incorrect. The statement can also evaluate to True if Button B is pressed.

Incorrect. That would require the ‘and’ operator instead of ‘or’.

Correct. The logical ‘or’ operator returns True if at least one of the conditions is true.

Incorrect. If neither is pressed, the code branches to the ‘else’ block and clears the display.


5.9. Question 9

Look at the following selection control structure:

if button_a.is_pressed():
    display.show("A")
elif button_b.is_pressed():
    display.show("B")
else:
    display.show("C")

If neither Button A nor Button B is pressed, what will be displayed on the micro:bit?

Incorrect. The “if” condition requires Button A to be pressed.

Incorrect. The “elif” condition requires Button B to be pressed.

Correct. When all preceding conditions in an if-elif chain evaluate to False, the final “else” block executes by default.

Incorrect. The “else” block explicitly runs display.show(“C”).


5.10. Question 10

Which of the following code blocks will display the letter “A” when Button A is pressed, display the letter “B” when Button B is pressed, and keep the screen clear when neither button is pressed?

Correct. This properly routes each button state and uses the else clause to clear the screen when both conditions evaluate to False.

Incorrect. Using two independent if statements means if Button A is pressed, the second if condition is evaluated separately, causing the else block to execute and clear the screen immediately.

Incorrect. This block lacks an final else structural branch to clear the screen when idle.

Incorrect. This checks if both buttons are held together, rather than handling them as separate, distinct button inputs.