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 | |
|---|---|---|
| 1if age >= 18: if has_id: print("Enter") | AA nested if: the inner if has_id is only checked when the outer condition age >= 18 is True | |
| 2if score >= 50 and attempts <= 3: print("Pass") | Btemp = 15 if temp > 20: if temp > 30: print("Hot") | |
| 3The inner if is indented one extra level (4 spaces) so Python knows it belongs inside the outer if block | CA single if using and: the same result as a nested if, but both conditions are joined on one line | |
| 4If the outer condition is False, the inner if is skipped and never checked | DThe inner if is not indented, so it is not inside the outer if block. Python raises an IndentationError because the outer block is empty. | |
| 5if age >= 18: if has_id: print("Enter") | Eif logged_in: if is_admin: print("Admin panel") | |
| 6if x > 0: if x < 10 print("Small") | FThe inner if is missing the colon at the end of its condition, which causes a SyntaxError. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
nested if — An if statement indented inside another if block. The inner condition is only checked when the outer condition is True.if age >= 18:
if has_licence:
print("Can drive")if score >= 50:
if score >= 90:
print("Distinction")if age >= 18 and has_licence:
print("Can drive")if x > 0:
if x % 2 == 0:
print("Positive even")if mark >= 50:
if mark == 100:
print("Perfect score")