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 | |
|---|---|---|
| 1if value.strip() == '': | Aif name.strip() == '': print('Name is required') | |
| 2if len(items) == 0: | BA single = is assignment and causes a syntax error. A comparison needs ==, as in value.strip() == ''. | |
| 3Show an error message when a required field is left blank | CExistence check: True when the input is empty or only spaces, so nothing real was entered | |
| 4Stop space-only input from passing an existence check by removing the spaces first | DWithout strip(), a space-only input is not equal to '', so the existence check wrongly passes. Use value.strip() == ''. | |
| 5if value == '': print('Missing') # user types three spaces | Etext = input('Enter: ').strip() | |
| 6if value.strip() = '': | FExistence check on a list: True when the list holds no items, so there is no data to use |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if value.strip() == '': — An existence check tests that a value was actually entered. strip() removes spaces, so this is True for empty or space-only input, and an error message can be shown.value = input("Enter your name: ")
if value.strip() == '':
print("Please enter a value")name = input("Name: ")
if name.strip() == '':
print("Name is required")scores = []
if len(scores) == 0:
print("No scores entered")city = input("City: ")
if city.strip() == '':
print("City is missing")import os
if not os.path.exists("data.csv"):
print("File not found")