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 | |
|---|---|---|
| 1while True: | AThe condition is the wrong way round. UNTIL Num >= 1 should become if Num >= 1: break, but this stops on invalid input. | |
| 2if Guess == 7: break | Bwhile True: Age = int(input()) if Age >= 0: break | |
| 3A REPEAT loop always runs its body at least once, because the test comes at the end. In Python the body goes straight after while True: | CThe if and break are not indented, so they are outside the loop. The loop never stops and break causes an error. | |
| 4UNTIL Score >= 50 becomes an if test with the same condition, followed by break. The loop stops when this is True. | DThe end-of-loop test that copies UNTIL Guess = 7. When the condition is True, the loop stops. | |
| 5while True: Num = int(input()) if Num > 0: break | Eif Score >= 50: break | |
| 6while True: Num = int(input()) if Num < 1: break | FStarts a loop that keeps repeating until a break stops it, so the body always runs at least once. This is Python's version of REPEAT. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
while True: — Python's version of REPEAT ... UNTIL: the body runs at least once, then an if with break at the end stops the loop when the UNTIL condition is True.while True:
name = input("Name: ")
if name != "": breakwhile True:
pin = input("PIN: ")
if pin == "1234": breakwhile True:
score = int(input("Score: "))
if score >= 50: breakwhile True:
n = int(input("Enter 1-10: "))
if 1 <= n <= 10: breakwhile True:
n = int(input("Number: "))
if n == 0: break