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 | |
|---|---|---|
| 1open('missing.txt') | AOutput: Missing | |
| 2try: f = open('f.txt') except: pass f.read() | BValid: Handle missing file | |
| 3try: f = open('f.txt') except FileNotFoundError: print('Not found') | COutput: FileNotFoundError | |
| 4try: open('f.txt') finally: print('done') | DError: f may not be defined | |
| 5try: open('x.txt') except FileNotFoundError: print('Missing') | EError: FileNotFoundError | |
| 6try: open('x.txt') except Exception as e: print(type(e).__name__) | FOk: finally always runs |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
FileNotFoundError — Error when trying to read a file that doesn't exist.~~PermissionErrortry:
with open('f.txt') as f:
print(f.read())
except FileNotFoundError:
print('Not found')try:
with open('f.txt') as f:
print(f.read())
except Exception as e:
print(e)try:
f = open('f.txt')
except FileNotFoundError:
print('Missing')try:
with open('f.txt') as f:
print(f.read())
except PermissionError:
print('No access')try:
open('f.txt')
except FileNotFoundError:
print('Missing')
finally:
print('Done')