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 | |
|---|---|---|
| 1choice in ['a', 'b', 'c'] | AGives True only if choice matches one of the allowed values in the list | |
| 2if choice not in options: | BThe allowed values are not inside a list. They need square brackets, like ['1', '2', '3']. | |
| 3Accept a menu choice only if it is one of the allowed options | Cif choice in ['1', '2', '3']: | |
| 4Make the list check case-insensitive so 'Y' and 'y' are both accepted | DRuns the indented block when the value is missing from the allowed list, so it can be rejected | |
| 5if choice in '1', '2', '3': | Eif answer.lower() in ['y', 'n']: | |
| 6if answer in ['y', 'n']: # user types 'Y' | FThe check is case-sensitive, so 'Y' is rejected. Use answer.lower() in ['y', 'n'] to accept any case. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
in — A list check uses in to accept a value only if it appears in a list of allowed values, e.g. choice in ['a', 'b']. Use not in to reject a value that is missing.if choice in ["a", "b", "c"]:if choice not in ["a", "b", "c"]:if choice.lower() in ["y", "n"]:options = ["pizza", "pasta", "salad"]
meal = input("Meal: ")
if meal in options:ok = ["red", "green", "blue"]
colour = input("Colour: ")
print(colour in ok)