A programmer is writing a system to locate an empty parking space in a 4 by 4 parking grid.
The code used is shown in Figure 1 and the current state of the grid is shown in Figure 2.
Figure 1
for r in range(4):
for c in range(4):
if check_space(r, c) == "Empty":
target_row = r
target_col = c
Figure 2
| Column 0 | Column 1 | Column 2 | Column 3 | |
|---|---|---|---|---|
| Row 0 | Occupied | Occupied | Occupied | Occupied |
| Row 1 | Occupied | Occupied | Occupied | Occupied |
| Row 2 | Occupied | Empty | Occupied | Occupied |
| Row 3 | Occupied | Occupied | Occupied | Occupied |
Explain the purpose of the second iteration structure (for c in range(4):) in the program in Figure 1.
298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.