Quiz - 39 File handling
Quiz - 39 File handling
Science
File handling
teachcomputerscience.co
m
Quiz
2. What happens when you try to open a file that does not
exist using the code?
with open("test.txt",'w') as f:
A. A new file is created
B. Error message pops up
C. Nothing happens
D. None of the above
teachcomputerscience.co
m
Use the file test1.txt to answer questions 4-6
teachcomputerscience.co
m
7. Which of the following prints contents of a file line by line?
A. with open("test.txt") as f:
for line in f:
print(line, end='')
B. with open("test.txt“,’w’) as f:
for line in f:
print(line, end='')
C. with open("test.txt“, ‘r’) as f
for line in f
print(line, end='')
D. with open("test.txt") as f:
f.read()
teachcomputerscience.co
m
Answers
Question
Answer
Number
1 B
2 A
3 C
4 C
5 B
6 A
7 A
8 D
teachcomputerscience.co
m