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 quit branch never uses break, so the loop never ends and the menu keeps appearing after the user chooses quit. | |
| 2elif choice == "2": | BStarts a menu loop that keeps showing the menu until the program reaches a break | |
| 3An invalid choice is handled by an else branch that shows an error and lets the loop repeat | Celse: print("Invalid choice") | |
| 4The quit option ends the menu loop and returns control to the rest of the program | DChecks whether the user picked option 2 and, if so, runs that option's function | |
| 5while True: choice = input("Choice: ") if choice == "3": print("Bye") | EA single = assigns a value instead of comparing. The condition needs == to check the user's choice. | |
| 6while True: choice = input("Choice: ") if choice = "1": add_item() | Felif choice == "3": break |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
while True: — Starts a menu loop that repeats forever: show options, read a choice, call the matching function with if/elif, reject invalid input, and break when the user picks quit.while True:
choice = input("Choice: ")
if choice == "1": if choice == "1":
addItem()
elif choice == "2": elif choice == "q":
break
else: elif choice == "3":
break
else:while True:
showMenu()
choice = input("Choice: ")