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 i in range(10): print(i) | AA while loop: use it when repeating depends on a condition that can change, like until the user types quit | |
| 2while answer != "quit": answer = input("> ") | BA while loop needs a condition that can change, not range(). For a fixed count of 10, use a for loop: for i in range(10): | |
| 3You know in advance that you want to repeat exactly 5 times, so choose a for loop | Cfor turn in range(5): | |
| 4A while loop may run zero times if its condition is False the very first time it is checked | DA for loop: use it when you know the loop must run a fixed number of times, such as 10 | |
| 5while i in range(10): print(i) | EA for loop cannot repeat until a condition changes. Use while answer != "quit": because we do not know how many times the user will type. | |
| 6for answer != "quit": answer = input("> ") | Flives = 0 while lives > 0: |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
for vs while — Use for when you know how many times to repeat, like 10 times. Use while when repeating depends on a condition that can change, like until the user types quit.for i in range(10):
print("Hello")command = input("Command: ")
while command != "quit":
command = input("Command: ")for i in range(0):
print("Hi")
print("Done")word = ""
while word != "quit":
word = input("Type: ")# Show Go! 10 times
for i in range(10):
print("Go!")