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 | |
|---|---|---|
| 1break | AThere is no break, so the loop never ends and the program runs forever. Add an if statement with break inside the loop. | |
| 2while True: | Bwhile True: break print('Done') | |
| 3Exit a loop when the user types 'quit' | Cif answer == 'quit': break | |
| 4The line after the loop runs once break has ended the loop | DStarts a loop that keeps running forever until a break is reached | |
| 5while True: name = input('Name: ') print(name) | EThe break is not indented, so it is outside the loop and cannot end it. It must be indented inside the loop, usually under an if. | |
| 6while True: age = int(input('Age: ')) break | FStops the loop it is in straight away and jumps to the first line after the loop |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
break — A keyword that stops the loop it is in straight away. The program then carries on with the first line after the loop. It is often used inside while True to exit when a condition is met.while True:
if input("Quit? ") == "y":
breakwhile True:
if input("Quit? ") == "y":
breakwhile True:
if input("Quit? ") == "y":
breakwhile True:
if int(input("Guess: ")) == 7:
breakwhile True:
if input("Quit? ") == "y":
break