Python File handling - Text file Quiz
Quiz
•
Computers
•
12th Grade
•
Practice Problem
•
Hard
Sathasivan H
Used 16+ times
FREE Resource
Student preview

20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following command is used to open a file “c:\temp.txt” in read-mode only?
infile = open(“c:\temp.txt”, “r”)
infile = open(“c:\\temp.txt”, “r”)
infile = open(file = “c:\temp.txt”, “r+”)
infile = open(file = “c:\\temp.txt”, “r+”)
2.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following command is used to open a file “c:\temp.txt” in write-mode only?
outfile = open(“c:\temp.txt”, “w”)
outfile = open(“c:\\temp.txt”, “w”)
outfile = open(file = “c:\temp.txt”, “w+”)
outfile = open(file = “c:\\temp.txt”, “w+”)
3.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following command is used to open a file “c:\temp.txt” in append-mode?
outfile = open(“c:/temp.txt”, “a”)
outfile = open(“c:\temp.txt”, “w+”)
outfile = open(“c:\\temp.txt”, “a”)
outfile = open(“c:\\temp.txt”, “r+”)
4.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following statements are true regarding the opening modes of a file?
A. When you open a file for reading, if the file does not exist, an error occurs.
B. When you open a file for writing, if the file does not exist, an error occurs.
C. When you open a file for reading, if the file does not exist, the program will open an empty file.
D. When you open a file for writing, if the file does not exist, a new file is created.
E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
Only A
A and B
A, D and E
A, B and E
5.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?
file.read(n)
n = file.read()
file.readline(n)
file.readlines()
6.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
7.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Popular Resources on Wayground
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
4:3 Model Multiplication of Decimals by Whole Numbers
Quiz
•
5th Grade
10 questions
The Best Christmas Pageant Ever Chapters 1 & 2
Quiz
•
4th Grade
12 questions
Unit 4 Review Day
Quiz
•
3rd Grade
20 questions
Christmas Trivia
Quiz
•
6th - 8th Grade
18 questions
Kids Christmas Trivia
Quiz
•
KG - 5th Grade
14 questions
Christmas Trivia
Quiz
•
5th Grade
15 questions
Solving Equations with Variables on Both Sides Review
Quiz
•
8th Grade