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 | |
|---|---|---|
| 1age.isdigit() | AReturns True only if the string age contains digits only, so it passes as a whole number | |
| 2int(value) | Bif not score.isdigit(): print("Enter a number") | |
| 3Reject text where a number is needed by testing the string before using it | CThe except block has no try before it, so int(value) is not protected and the code is a syntax error. | |
| 4Use try/except to catch input that cannot be converted to an integer | Disdigit() is a string method, so it must be called on the string as age.isdigit(), not as a stand-alone function. | |
| 5if isdigit(age): | ETries to convert text to a whole number and raises ValueError if it cannot | |
| 6n = int(value) except ValueError: | Ftry: n = int(value) except ValueError: print("Not a number") |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
isdigit() — A type check method: returns True if a string holds only digits, so text can be rejected where a number is needed. The alternative is to put int(value) inside try/except.age = input("Age: ")
if age.isdigit():
print("Age accepted")try:
age = int(input("Age: "))
except ValueError:try:
score = int(entry)
except ValueError:if not age.isdigit():
print("Numbers only!")try:
num = int(value)
except ValueError: