6. For Loops Quiz

6.1. Question 1

When iterating over a string using for char in welcome_string:, what value is stored in the variable char on each step of the loop?

Incorrect. The loop yields individual characters, not the overall count.

Incorrect. A loop breaks the collection down element by element.

Correct. The text explains that each character in the string is placed in the variable in turn.

Incorrect. It extracts the character contents directly, not their numerical index values.


6.2. Question 2

Look at this code example from the text:

welcome_string = 'Hello'
while True:
    for welcome_character in welcome_string:
        display.scroll(welcome_character)
    sleep(300)

What is the physical display outcome on the micro:bit matrix?

Incorrect. Because it is inside a for loop, it scrolls character by character.

Correct. The for loop forces each character to scroll separately before hitting the 300ms pause.

Incorrect. The display.scroll() function causes text to move horizontally.

Incorrect. This is correct syntax and will repeat indefinitely.


6.3. Question 3

What parameter does the basic range(5) function take, and what sequence of integers does it generate?

Incorrect. Python ranges start at 0 by default and stop before the end value.

Correct. The text demonstrates that range(5) provides integers from 0 up to, but not including, 5.

Incorrect. Without a third argument, the default increment step size is 1.

Incorrect. It generates an arithmetic progression sequence.


6.4. Question 4

How must a nested loop structure be arranged to visit every coordinate location on the 5x5 micro:bit LED display grid?

Incorrect. Separate loops cannot iterate over coordinate combinations efficiently.

Correct. The exercises demonstrate nesting an inner for x in range(5) loop inside an outer for y in range(5) loop to check all pixels.

Incorrect. This is invalid syntax for traversing a multi-dimensional pixel grid.

Incorrect. Iteration must be specified explicitly in code blocks.


6.5. Question 5

Which function is used to set the individual brightness level of a specific LED on the micro:bit grid?

Incorrect. This function name does not exist in the micro:bit library.

Correct. The documentation challenges show that display.set_pixel() targets specific row and column coordinates.

Incorrect. Scrolling is an automated text/sequence function, not an individual LED setup tool.

Incorrect. This is incorrect method syntax.


6.6. Question 6

What are the valid boundary numbers for the coordinate positions and brightness arguments when using display.set_pixel(x, y, brightness)?

Incorrect. Python structures use zero-indexed numbers for coordinates.

Incorrect. 5 is outside the index range for a 5x5 grid (0-4), and brightness starts at 0.

Correct. A 5x5 grid runs from index 0 to 4, and brightness ranges from 0 (off) to 9 (maximum bright).

Incorrect. The grid does not use centered negative coordinates.


6.7. Question 7

Look at the following code block from the documentation solutions:

for y in range(5):
    for x in range(5):
        display.set_pixel(x, y, 9)
        sleep(100)

In what specific order will the LEDs light up on the display?

Incorrect. The sleep statement introduces a delay between actions.

Incorrect. The outer loop controls the row, so rows take priority.

Correct. The outer loop holds the row index (y) steady while the inner loop cycles across all columns (x) first.

Incorrect. The numbers generated by range() follow a strict linear sequence.


6.8. Question 8

What happens if you change the inner loop statement from display.set_pixel(x, y, 9) to display.set_pixel(x, y, 0) in the grid filling program?

Incorrect. 0 sets the brightness level to completely off.

Correct. Setting the brightness value parameter to 0 turns off that specific targeted pixel.

Incorrect. 0 is a valid brightness argument.

Incorrect. Animation speed is controlled exclusively by the sleep duration.


6.9. Question 9

Why is a 2D grid template list of list structures useful when working with micro:bit images, as shown in the advanced tasks?

heart = [

Incorrect. Data layouts do not boost processor hardware speeds.

Correct. The 1s and 0s mimic the physical arrangement of the 5x5 LED panel, making layout mapping intuitive.

Incorrect. Lists do not perform type translation tasks.

Incorrect. Run cycles are determined by loop conditions, not the variable data style.


6.10. Question 10

How can you capture and store the coordinates of active pixels dynamically during a nested loop traversal so you can manipulate them later?

Incorrect. Strings store flat text characters and cannot easily isolate pairs.

Incorrect. Loop boundaries stay fixed during execution.

Correct. The tasks demonstrate tracking active units by appending coordinate pairs to a list object, which can then be picked or popped.

Incorrect. Brightness cannot exceed 9 and does not track historical records.