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 name != "": | Aname = input("Name: ") while name == "": name = input("Name: ") | |
| 2if len(name) > 0: | BA single = assigns a value instead of comparing. Use == to test for an empty string, or != "" to check the user entered something. | |
| 3An empty string means the user pressed Enter without typing anything, so the existence check fails | CChecks that the input has at least one character, so it passes the existence check | |
| 4To re-ask until something is entered, loop while the input is still empty | DA length can never be less than 0, so this check never works. It should be len(name) > 0 to confirm something was entered. | |
| 5if name = "": | EChecks that the user typed something, because the input is not an empty string | |
| 6if len(name) < 0: | Fname = input("Name: ") if name == "": print("Required") |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if name != "" — An existence check tests that the user actually entered something, so the input is not an empty string. len(name) > 0 does the same job. Loop and re-ask until it passes.name = input("Enter your name: ")
if name != "":
print("Thanks,", name)name = input("Enter your name: ")
if len(name) > 0:
print("Hello", name)name = input("Name: ")
while name == "":
name = input("Name: ")name = input("Enter name: ")
while len(name) == 0:
name = input("Enter name: ")name = input("Enter name: ")
while name == "":
name = input("Enter name: ")