Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1for row in rows: print(f"{row[0]:<10}{row[1]}") | AChecks whether the query returned no rows and shows a no records found message instead of a blank screen | |
| 2if len(rows) == 0: print("No records found") | BLoops over every fetched row and prints its fields, with the first field padded to 10 characters so the columns line up | |
| 3Print column headings once, before the loop, using the same widths as the data rows so the headings sit above the columns | CThe no records message is inside the loop, so it prints once for every row and never appears when the list is empty because the loop body does not run. | |
| 4Show each fetched row with its fields in aligned columns by looping over the list of rows | DIt uses rows (the whole list) instead of row (the current row), so every pass prints the same first two records instead of each row's own fields. | |
| 5for row in rows: print(f"{rows[0]:<10}{rows[1]}") | Efor row in rows: print(f"{row[0]:<10}{row[1]}") | |
| 6for row in rows: print("No records found") | Fprint(f"{'Name':<10}{'Points'}") |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
for row in rows: print(f"{row[0]:<10}{row[1]}") — Loops over each fetched row and prints its fields with an f-string, padded into columns so results are readable. Check for an empty list to show a no records message.for row in rows:
print(f"{row[0]:<10}{row[1]}")for row in rows:
print(f"{row[0]:<10}{row[1]}")print(f"{'Name':<10}{'Mark'}")if len(rows) == 0:
print("No records found")for row in rows:
print(f"{row[0]:<10}{row[1]}")