5. Buttons and Selection Quiz
5.1. Question 1
What is the primary operational difference between the .is_pressed() method and the .was_pressed() method?
Incorrect. They track button states using different historical timing logic.
Correct. The text outlines that .is_pressed looks at the active moment, whereas .was_pressed tracks state history since the last device check.
Incorrect. Both require active live execution on powered hardware.
Incorrect. Any delays must be programmed explicitly using sleep statements.
5.2. Question 2
What data type is returned when evaluating a button checking method like button_a.is_pressed()?
Incorrect. It does not return text characters inside quotation marks.
Incorrect. It does not output raw whole numbers like 1 or 0.
Correct. The documentation explicitly states that it returns either
TrueorFalse.
Incorrect. It does not return fractional decimal numbers.
5.3. Question 3
Look at the following selection control block code:
if button_a.is_pressed():
display.show("A")
elif button_b.is_pressed():
display.show("B")
What occurs if a user presses both Button A and Button B down at the exact same fraction of a second?
Incorrect. An if-elif chain stops evaluating after finding its first matching match.
Correct. Because the
ifcondition is evaluated first, its block triggers and theelifbranch for Button B is skipped entirely.
Incorrect. This is structured logically and will not crash.
Incorrect. No graphic combinations occur unless explicitly programmed.
5.4. Question 4
Which of the following code patterns checks if BOTH buttons are being held down simultaneously?
Correct. The
andlogical operator requires both individual button states to evaluate to True at the same time.
Incorrect. The
oroperator requires only one or the other button to be down, not necessarily both.
Incorrect. Combining button conditional methods with addition operators is improper syntax.
Incorrect. This checks if either button had a historical click event independently.
5.5. Question 5
What is the purpose of using the min() and max() functions when updating game variables like a guess_number?
Incorrect. Math boundaries do not alter physical code execution velocities.
Correct. The tasks demonstrate using functions like
min(9, guess_number + 1)to prevent values from skipping outside specified limits.
Incorrect. Variable cleanup is handled natively by the runtime environment.
Incorrect. Numeric display limits are dictated by matrix resolutions.
5.6. Question 6
Consider the following program loop:
while True:
if button_a.was_pressed():
display.show("A")
else:
sleep(100)
Why is the sleep(100) statement placed inside the else: clause block?
Incorrect. Sleeping intentionally slows processing down.
Incorrect. Clearing requires explicit command lines like
display.clear().
Correct. It stops the loop from running at maximum speed when idle, which provides efficiency pauses.
Incorrect. A
while Truecontainer loops infinitely until forced by a break statement.
5.7. Question 7
What happens to the internal click history counter immediately after you call the button_a.was_pressed() method?
Incorrect. It does not accumulate continuously after interrogation.
Correct. Calling
.was_pressed()clears the history buffer status so it can start fresh tracking for future clicks.
Incorrect. System delays are governed strictly by sleep statements.
Incorrect. Buttons stay continuously receptive during standard loop cycles.
5.8. Question 8
A student writes the code block below to increase a score value when pressing Button A:
# Start value
score = 5
if button_a.was_pressed():
score = min(9, score + 2)
If the current value of score is 8, and the user presses Button A, what is the new value stored inside score?
Incorrect. The bounding check sets a structural cap that prevents it from reaching 10.
Incorrect. The baseline number increases because it has space before hitting the absolute ceiling limit.
Correct. Adding 2 to 8 yields 10, but
min(9, 10)returns 9, limiting the value to the max boundary.
Incorrect. The value updates upward rather than resetting to its base initial state.
5.9. Question 9
Which of the following code blocks demonstrates the correct way to continuously decrease a variable called level by a step of 1 down to a minimum floor value of 1 using Button B?
Correct. Subtracting 1 decreases the value, and passing it to
max(1, ...)ensures it cannot fall below 1.
Incorrect. This forces the level to immediately drop to 1 or lower.
Incorrect. This adds to the level variable and checks against an incorrect upper constraint.
Incorrect. This fails to implement a safety ceiling or floor value constraint entirely.
5.10. Question 10
If you run code that contains an infinite while True: loop without adding any internal sleep() delays or scrolling actions, what is the resulting negative outcome?
Incorrect. Program tracking logic does not modify code storage spaces.
Incorrect. Formatting layouts are not dynamically inverted by processor load.
Correct. Including minor delay offsets keeps processing loops efficient.
Incorrect. Micro:bits can always be safely rewritten with fresh code flashing sequences.