File Handling

Download as pdf or txt
Download as pdf or txt
You are on page 1of 138

Name of the Chapter- DATA FILE HANDLING

Question Question Content Learning Objective(if


No Provided)
Q1. Suppose content of ‘mytext.txt’ file is: Knowledge

What will be the output of the following code?


file = open(“mytext.txt”, ‘r’)
txt = file.read()
print(file.read(10))

(A) The key to


(B) obstacles.
(C) Error
(D No Output
Q2. Consider the following directory structure: Application

There are three directories under root directory ‘Admin’.


The current working directory is Final. Identify the
relative path name for file ‘Result1.xlsx’.
(A) .\Result1.xlsx
(B) Admin\Final\First Term\Result1.xlsx
(C) ..\First Term\Result1.xlsx
(D) First Term\Result1.xlsx

Q3. Which of the following statements is correct regarding Understanding


file access modes?
(A) In ‘r’ mode, we can read and write data from/in the
file.
(B) In ‘a’ mode, the existing data will be over-written if
the file exists.
(C) In ‘w’ mode, the data in the file is retained and new
data will be appended to the end.
(D) In ‘a+’ mode, both reading and writing operations can
take place and new data is appended to the end of the
existing file.

Q4. Consider a statement Understanding


fileobj = open(“myblog.txt”, ‘r’)
Which of the following options can be used to print the
last line of a text file ‘myblog.txt’?
(A) print(fileobj.readlines() -1)
(B) disp = fileobj.readlines()
print(disp[-1])
(C) print(fileobj.readlines(-1))
(D) print(fileobj.read(-1))

Q5. Which of the following statements is used to open a text Understanding


file to add new contents at the end of the already existing
text file named ‘mydiary.txt’?
(i) with open(“’mydiary.txt”, ‘w’) as fileobj:
(ii) fileobj = open(“mydiary.txt”, ‘a’)
(iii) with open(“mydiary.txt”,’a’) as fileobj:
(iv) with open(“mydiary”, ‘r+’) as fileobj:

(A) Only (i)


(B) Only (ii)
(C) Both (ii) and (iii)
(D) Both (i) and (iv)

Q6. “The information is stored in machine-readable format Understanding


and pickle module is used for reading and writing
data from/in the file.”
Identify the type of file discussed in the above lines?
(A) Text files
(B) CSV files
(C) Binary file
(D) All of the above

Q7. Assume that you are writing in a text file; now you want Knowledge
to identify where the cursor is currently at in the
file. Which function will you use for the same?
(A) seek()
(B) hide()
(C) tell()
(D) type()
Q8. Consider the statements given below: Evaluation
Fileobj = open(“Report.txt”, ‘r’)
Fileobj.seek(25,0)
Choose the statement that best explains the second
statement.
(A) It will place the pointer at 25 bytes ahead of the
current file pointer position.
(B) It will place the pointer at 25 bytes behind from the
end-of file.
(C) It will place the pointer at 25 bytes from the
beginning of the file.
(D) It returns 25 characters from the 0th index.

Q9. To read 4th line from text file, which of the following Knowledge
statement is true?
(A) dt = f.readlines();print(dt[3])
(B) dt=f.read(4) ;print(dt[3])
(C) dt=f.readline(4);print(dt[3])
(D) All of these

Q10. Which of the following groups of functions belongs to Application


CSV module?
(A) reader(), writer()
(B) readlines(), writelines()
(C) writerow(), read()
(D) writer(), readline()

Q11. Which is/are the basic I/O (input-output) stream(s) in Application


file?

(A) Standard Input


(B) Standard Output
(C) Standard Errors
(D) All of the above
Q12. Consider the content of the file ‘Story.txt’: Application

What is the output of the following code?


Fileobj = open("story.txt", 'r')
S1= Fileobj.read(20)
S2= Fileobj.tell()
Fileobj.seek(34,0)
S3= Fileobj.read(20)
print(S3)

(A) The Tortoise meanwhi


(B) slowly but steadily
(C) Hare was sleeping
(D) he Tortoise in time

Q13. Consider a file “online.txt” Evaluation

What will be the output of the following code?


fileobj=open('online.txt','r')
count = 0
l=fileobj.readline()
for i in l:
if 'o' in i:
count=count+1
print(count)
fileobj.close()

(A) 10
(B) 8
(C) 9
(D) 20

Q14. Which function is used to write all the characters? Understanding

(A) write()
(B) writecharacters()
(C) writeall()
(D) writechar()

Q15. What is the difference between r+ and w+ modes? Knowledge

(A) No difference.
(B) In r+ mode, the pointer is initially placed at the
beginning of the file and for w+, the pointer is placed at
the end.
(C) In w+ mode, the pointer is initially placed at the
beginning of the file and for r+, the pointer is placed at
the end.
(D) Depends on the operating system.

Q16 Information stored on a storage device with a specific


name. is called a
A. Array
B. Dictionary
C. file
D. tuple

Q17 EOL stands for


A. End of Lines
B. End Of Line
C. End Of List
D. End Of Location

Q18 Which of the following file types allows to store large


data files in the computer memory?
A. Text Files
B. Binary Files
C. CSV Files
D. None of these

Q19 Which of the following functions transfer the data to file


before closing the file?
A. flush()
B. close()
C. open()
D. fflush()

Q20 Which of the following is not a known file type?


A. csv
B. pdf
C. txt
D. txp

Q21 Which of the following not a valid file extension for file
student?
A. student.txt
B. student.cvc
C. student.dat
D. student.pdf

Q22 Which of the following is not a correct statement for


binary files?
A. Easy for carrying data into buffer
B. Much faster than other file systems
C. Every line ends with new line character ‘\n’
D. Characters translation is not required

Q23 Which of the following file types can be opened with


notepad as well as ms excel?
A. Text Files
B. CSV Files
C. Binary Files
D. None of these

Q24 Which of the following format of files can be created


programmatically through python to store some data?
A. Pdf file
B. Audio file
C. Binary file
D. Video file

Q25 Which file can open in any text editor and is in human
readable form?
A. Binary files
B. Text files
C. Data files
D. d. Video files

Q26 _________ is a file format which stores records separated


by comma.
A. .tsv
B. .csv
C. .py
D. .bin
Q27 The CSV files can be operated by _______software.
A. Spreadsheet
B. Notepad
C. MS Excel
D. All of the above

Q28 Which of the following parameter needs to be added with


open function to avoid blank row followed file each row
in CSV file?
A. delimiter
B. newline
C. writer, delimiter
D. file object

Q29 12. Default EOL character in Python.


A. ‘\n’
B. ‘\r’
C. ‘’
D. ‘\t’

Q30 Trying to open a binary file using a text editor will show:
A. Garbage values
B. ASCII values
C. Binary character
D. Unicodes

Q31 Choose the correct syntax to open a file in write mode. KNOWLEDGE AND
(A) f.open(“file.txt”,’w’) UNDERSTANDING
(B) f = open(“file.txt”)
(C) f = open(“file.txt”,’w’)
(D) f = open(“file.txt”, ‘r’)
Q32 Choose the correct syntax to open a file in append mode. KNOWLEDGE AND
(A) with open(“file.txt”, “a”) as f : UNDERSTANDING
(B) with open(“file.txt”) as “f”
(C) with open(“file.txt”, “a”) as f
(D) with open(“file.txt”, “w”) as f :
Q33 Which of the following is not a valid file access mode? KNOWLEDGE AND
(A) a+ UNDERSTANDING
(B) r
(C) w
(D) b+
Q34 Choose the correct syntax to close a file. KNOWLEDGE AND
(A) f.closed UNDERSTANDING
(B) f.close()
(C) f.closed()
(D) f.close
Q35 Which method is used to write multiple strings/lines in a KNOWLEDGE AND
text file? UNDERSTANDING
(A) write()
(B) writeline()
(C) writelines()
(D) writesingle()
Q36 Which method is used to write a single string/line in a KNOWLEDGE AND
text file? UNDERSTANDING
(A) write()
(B) writeline()
(C) writelines()
(D) writesingle()
Q37 Which of the following statements is correct? KNOWLEDGE AND
(A) In r+ mode, a file opens for both reading and writing UNDERSTANDING
if it already exists. The file pointer placed at the
beginning of the file.
(B) In w+ mode, a file opens for both writing and
reading. Overwrites the existing file if the file exists. If
the file does not exist, create a new file for reading and
writing.
(C) Both of the above
(D) None of the above
Q38 By default, in which mode a file open. KNOWLEDGE AND
(A) r UNDERSTANDING
(B) w
(C) a
(D) None of the above
Q39 While using an open function in which mode a text file APPLICATION
will be created, if it does not exist already.
(A) r+
(B) w
(C) Both of the above
(D) None of the above
Q40 While using an open function in which mode a text file APPLICATION
will not be created, if it does not exist already.
(A) r+
(B) r
(C) Both of the above
(D) None of the above
Q41 Which of the following iterable objects can be passed to APPLICATION
the writelines() method for writing multiple lines/strings
in a text file.
(A) list
(B) tuple
(C) Both of the above
(D) None of the above
Q42 Which of the following is not a correct statement? APPLICATION
(A) write and append modes opens file for writing.
(B) In both modes file pointer for existing file sets to
beginning of file, when opened.
(C) In append mode existing data do not get overwritten,
whereas in writing mode existing data gets overwritten.
(D) By adding ‘+’ symbol both can be able to open files
in reading mode also.
Q43 A user opened a file using code : f = open(“story.txt”,’r’) ANALYSIS,
But the file “story.txt” does not get opened. Find the EVALUATION AND
appropriate reason for not opening the file. CREATION
(A) There is a syntax error in the code.
(B) File pointer name is not correct.
(C) User need to include the absolute path of file location.
(D) File does not exist.
Q44 Consider the code: ANALYSIS,
lines = ['This is line 1', 'This is line 2'] EVALUATION AND
with open('readme.txt', 'w') as f: CREATION
f.writelines(lines)
Which of the following statements is true regarding the
content of the file ‘readme.txt’?
(A) Both strings of list lines will be written in two
different lines in the file ‘readme.txt’.
(B) Both strings of list lines will be written in the same
line in the file ‘readme.txt’.
(C) string 1 of list lines will overwrite string 2 of list lines
in the file ‘readme.txt’.
(D) string 2 of list lines will overwrite string 1 of list lines
in the file ‘readme.txt’.
Q45 Consider the code: ANALYSIS,
lines = ['This is line 1', 'This is line 2'] EVALUATION AND
with open('readme.txt', 'w') as f: CREATION
for line in lines:
f.write(line+’\n’)
Which of the following statements is true regarding the
content of the file ‘readme.txt’?
(A) Both strings of list lines will be written in two
different lines in the file ‘readme.txt’.
(B) Both strings of list lines will be written in the same
line in the file ‘readme.txt’.
(C) string 1 of list lines will overwrite string 2 of list lines
in the file ‘readme.txt’.
(D) string 2 of list lines will overwrite string 1 of list lines
in the file ‘readme.txt’.
Q46 What are the file types in Python?
(A) Text File Understanding
(B) TSV File
(C) CSV File
(D) All of the above
Q47. Which command is used to open a text file in Python in Analysis
reading mode?
(A) F = open( )
(B) F = open(“Data.Txt”,”w”)
(C) F = open(“Data.Txt,”r”)
(D) All of the Above
Q48 What is the use of File Object? Knowledge
(A) File Object Serves as a link to a file
(B) File Objects are used to read and write data to the file
(C) A file Object is a reference to a file on disk
(D) All of the above
Q49 Which is the default mode to open a file? Knowledge
(A) read mode
(B) r+ mode
(C) write mode
(D) w+ mode
Q50 Which mode creates a new file, when open file ? Understanding
(A) w+ mode
(B) a mode
(C) a+ mode
(D) All of the above
Q51 Which function is used to read the contents from a file? Knowledge
(A) read ( )
(B) write ( )
(C) close ( )
(D) None of these
Q52 Which of the following command is used to open a file Application
“C:\\Data.txt for writing as well as reading mode ?
(A) f = open(“c:\\pat.txt”,”w”)
(B) f = open(“c:\\pat.txt”,”wb”)
(C) f = open(“c:\\pat.txt”,”w+”)
(D) f = open(“c:\\pat.txt”,”wb+”)
Q53 Which function is used to write a list of strings in a file? Understanding
(A) writeline ( )
(B) writelines ( )
(C) writelist ( )
(D) writefulline ( )
Q54 When open a file in append mode, by default new data Analysis
can be added at the?
(A) Beginning of the file
(B) End of the file
(C) At the middle of the file
(D) All of the above
Q55. Find the output of the following code – Application
fp = open("sample.txt", "r")
fp.read(8)
print(fp.tell())
fp.close()

(A) 0
(B) 7
(C) 8
(D) 9
Q56 What will be the output of the following code if content application
of the file “smile.txt” is: Smiling is infectious,
You catch it like the flu.
When someone smiled at me today,
I started smiling too.
file=open(“smile.txt”)
contents=file. read()
print(file. read (7))
(A) Smiling
(B) Smilin
(C) ng too.
(D) No output
Q57 If the content of the file “wish.txt” is – “Happy”, then Application
what will be the content of the file after executing the
following statements –
f=open (“wish.txt”, ‘w’)
f. write(“Birthday”)
f. close()?
(A) Happy Birthday
(B) HappyBirthday
(C) Happy
(D) Birthday
Q58 Consider a code: Creation
Fileobj = open("story.txt", 'a')
x= 200
a= Fileobj.write(x)
Fileobj.close()
What is the output of the above given code?
(A) Generates an error : x must be string .
(B) It will write 200 at the end of the file.
(C) It will write 200 at the beginning of the file.
(D)It will delete the existing content and write 200 in the
beginning.

Q59 Consider a file “online.txt” Application


With educational institutes closed due to the COVID-19
pandemic, the government has been encouraging online
education to achieve academic continuity.
Online education allows for learning something beyond
the norm.
What will be the output of the following code?
fileobj=open('online.txt','r')
count = 0
l=fileobj.readline()
for i in l:
if 'o' in i:
count=count+1
print(count)
fileobj.close()
(A) 10
(B) 8
(C) 9
(D)20
Q60 Consider the content of ‘rhyme.txt’ file: Analysis

What will be the output of the following code?


fileobj=open(‘rhyme.txt','r')
count = 0
l=fileobj. readlines()
for i in l:
if(i[0]=='H'or i[0]==’T’):
count=count+1
print(count)
fileobj.close( )
(A) 4
(B) 2
(C) 3
(D) 1
Q61 Which of the following file mode will refer to the TEXT UNDERSTANDING
mode? KNOWLEDGE
ANALYSIS
(A) rb
(B) b
(C) b+
(D) w
Q62 The _____ file mode is used when user want to write data UNDERSTANDING
into Text file. KNOWLEDGE
(A) rb
(B) b
(C) b+
(D) w

Q63 The _____ file mode is used when user want to read and UNDERSTANDING
write data into Text file. KNOWLEDGE
(A) rb
(B) b
(C) r+
(D) w

Q64 The _____ file mode is used when user want to write and UNDERSTANDING
read data into Text file. KNOWLEDGE
(A) rb
(B) w+
(C) r+
(D) w

Q65 The _____ file mode is used when user want to append UNDERSTANDING
data into Text file. KNOWLEDGE
(A) rb
(B) w+
(C) r+
(D) a

Q66 Name the function to read from Text file. UNDERSTANDING


(A) read() KNOWLEDGE
(B) csv.reader() ANALYSIS
(C) csv.read()
(D) reader()

Q67 The correct syntax to read from Text file is__________ UNDERSTANDING
(A) <filehandle>.read() KNOWLEDGE
(B) read.(filehandle) ANALYSIS
(C) read(filehanle).txt
(D) None of the above
Q68 The correct syntax to reads a line of input from Text file UNDERSTANDING
is__________ KNOWLEDGE
(A) <filehandle>.read() ANALYSIS
(B) readline.(filehandle)
(C) read(filehanle).txt
(D) <filehandle>.readline()
Q69 The correct syntax to reads all lines of input from Text UNDERSTANDING
file and returns them in a list is __________ KNOWLEDGE
(A) <filehandle>.readlines() ANALYSIS
(B) readline.(filehandle)
(C) read(filehanle).txt
(D) <filehandle>.readline()
Q70 In which file, delimiters are used for line and translations UNDERSTANDING
occur? KNOWLEDGE
(A) Text file ANALYSIS
(B) Binary file
(C) Both are correct
(D) None of the above
Q71 observe the following code and answer the follow UNDERSTANDING
f1=open("mydata","a") KNOWLEDGE
______#blank1 ANALYSIS
f1.close()
what type of file is mydata?
(A) Text file
(B) Binary file
(C) Both are correct
(D) None of the above

Q72 observe the following code and answer the follow UNDERSTANDING
f1=open("mydata","a") KNOWLEDGE
______#blank1 ANALYSIS
f1.close()
Fill in the blank1 with correct statement to write "abc"
in the file "mydata"
(A) f1.write(“abc”)
(B) write(abc)
(C) write.f1(abc)
(D) None of the above

Q73 In which of the following file modes the existing data of UNDERSTANDING
the file will not be lost? KNOWLEDGE
(A) ab and a+b mode ANALYSIS
(B) r mode
(C) w mode
(D) None of the above
Q74 To take file pointer to nth character with respect to r UNDERSTANDING
position in seek method___ KNOWLEDGE
(A) f1.seek(r) ANALYSIS
(B) f1.seek(n)
(C) f1.seek(n,r)
(D) seek(n,r).f1

Q75 It returns the current position of cursor in the file UNDERSTANDING


(A) f1.tell() KNOWLEDGE
(B) f1.seekn(n) ANALYSIS
(C) f1.seek.tell(n,r)
(D) tell(n,r).f1
Sl No Questions Learning Objective
Q76 To read the entire contents of the file as a string Knowledge
from a file object fobj, the command should be:

(a) fobj.read(2)
(b) fobj.read()
(c) fobj.readline()
(d) fobj.readlines()
Q77 Which statement is used to change the file position Understanding
to an offset value from the start?

(a) fp.seek(offset, 0)
(b) fp.seek(offset, 1)
(c) fp.seek(offset, 2)
(d) None of the above
Q78 Which statement is used to retrieve the current Knowledge
position within the file?

(a) fp.seek()
(b) fp.tell()
(c) fp.loc
(d) fp.pos
Q79 What happens if no arguments are passed to the seek() Knowledge
method?
(a) file position is set to the start of file
(b) file position is set to the end of file
(c) file position remains unchanged
(d) results in an error

Q80
Which function is used to read single line from file? Knowledge

(a) readline()
(b) readlines()
(c) readstatement( )
(d) readfulline()
Q81 Which function is used to change the position of the Knowledge
File Handle to a given specific position.
a. seek()
b. read()
c. tail()
d. write()
Q82 What is the use of seek() method in files? Understanding
a) sets the file‟s current position at the offset
b) sets the file‟s previous position at the offset
c) sets the file‟s current position within the file
d) none of the mentioned
Q83 How do you change the file position to an offset Understanding
value from the start?
a) fp.seek(offset, 0)
b) fp.seek(offset, 1)
c) fp.seek(offset, 2)
d) none of the mentioned
Q84 How many arguments passed to the tell()? Knowledge
a. 0
b. 1
c. 2
d. variable number of arguments
Q85 How do you change the file position to an offset Understanding
value from the start?
a) fp.seek(offset, 0)
b) fp.seek(offset, 1)
c) fp.seek(offset, 2)
d) none of the mentioned
Q86 What happens if no arguments are passed to the Knowledge
seek function?
a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error
Q87 readlines() method return _________ Knowledge

a. String
b. List
c. Dictionary
d. Tuple
Q88 Which of the following method is used to read a specified Knowledge
number of bytes of data from a data file.
a. read( )
b. read(n)
c. readlines( )
d. reading(n)
Q89 Write the output of the following: Understanding

f=open("test.txt","w+")
f.write("File-Handling")
f.seek(0)
a=f.read(5)
print(a)

a. File-
b. File
c. File-H
d. No Output
Q90 Write the output of the following: Understanding

f=open("test.txt","w+")
f.write("FileHandling")
f.seek(0)
a=f.read(-1)
print(a)

a. File
b. Handling
c. FileHandling
d. No Output
Q91 Knowledge
Soumya is learning to use word processing software for
the first time. She creates a file with some text
formatting features using notepad. What type of file is
she working on?
A. Text file
B. CSV file
C. Binary file
D. All of the above
Q92 To read the remaining lines of the file from a file object F, Knowledge
we use
A. F.read
B. F.read()
C. F.readlines()
D. F.readline()
Q93 Which statement is used to retrieve the current position Knowledge
within file?
A. seek()
B. tell()
C. loc()
D. pos()
Q94 In text file each line is terminated by a special character Knowledge
called ?
A. EOL
B. END
C. Full Stop
D. EOF
Q95 What error is returned by following statement, if file Knowledge &
“try.txt” does not exist? understanding
f = open(“try.txt”)
A. Not Found
B. File Not Found Error
C. File Does Not Exist
D. No Error
Q96 To open a file c:/story.txt reading we Knowledge &
use_________________ understanding
A. F=open(‘c:/story.txt’,r)
B. F=open(‘c://story.txt’,r)
C. F=open(‘c:\story.txt’,r)
D. F=open(‘c:\\story.txt’,r)
Q97 Another name of file object is Knowledge
A. File handle
B. File name
C. No another name
D. File
Q98 Name the module required for Text Files knowledge
A. Pickle
B. CSV
C. String
D. No module required
Q99 To open a file Myfile.txt for appending , we can use understanding
A. F=open("Myfile.txt","a")
B. F=open(“Myfile.txt","w+")
C. F=open(r"d:\Myfolder\Myfile.txt","w")
D. F=open("Myfile.txt","w")
Q100 To read the 02 characters of the file from a file object F, Knowledge &
we use Application
A. F.read(2)
B. F.read()
C. F.readlines()
D. F.readline()
Q101 To read the next line of the file from a file object F, we Knowledge &
use Application
A. F.read(2)
B. F.read()
C. F.readlines()
D. F.readline()
Q102 The readlines() method returns Knowledge
A. String
B. A List of integers
C. A list of characters
D. A List of Lines
Q103 Knowledge &
Assume you are reading from a text file from the
Application
beginning and you have read 10 characters. Now you
want to start reading from the 50th character from the
beginning. Which function will you use to do the same?
A. seek(50,1)
B. seek(50,2)
C. seek(40,0)
D. seek(50,0)
Q104 Consider the content of the file ‘Story.txt’ Knowledge ,
understanding &
application

What is the output of the following code?


Fileobj = open("story.txt", 'r')
S1= Fileobj.read(20)
S2= Fileobj.tell()
Fileobj.seek(34,0)
S3= Fileobj.read(20)
print(S3)
A. The Tortoise meanwhi
B. slowly but steadily
C. Hare was sleeping
D. he Tortoise in time

Q105 Knowledge ,
Consider a file ‘rhyme.txt’
understanding &
application
What will be the output of the following code?
fileobj = open('forest.txt', 'r')
R1 = (fileobj.readline().split())
for word in R1:
for ch in range(len(word)-1,-1,-1):
print(word[ch],end='')
print(end='')
fileobj.close()
A. rewoPot.rewopmE
B. .rewopmE rewoPot
C. Empower. to Power
D. Power Empower. to
Q106 'n' characters from the file can be read by .................. Understanding
method
(A) readline(n)
(B) readlines(n)
(C) reads(n)
(D) read(n)
Q107 In which format does the readlines( ) function give the Knowledge
output?
(A) Integer type
(B) list type
(C) string type
(D) tuple type
Q108 Which of the following options can be used to read the Application
first line of a text file Myfile.txt?
(A) myfile = open('Myfile.txt');
myfile.read()
(B) myfile = open('Myfile.txt','r');
myfile.read(1)
(C) myfile = open('Myfile.txt');
myfile.readline()
(D) myfile = open('Myfile.txt');
myfile.readlines()
Q109 To read two characters from a file object infile, we use Application
____________
(A) infile.read(2)
(B) infile.read()
(C) infile.readline()
(D) infile.readlines()
Q110 To read the entire remaining contents of the file as a Application
string from a file object infile as string, we use
____________
(A) infile.read(2)
(B) infile.read()
(C) infile.readline()
(D) infile.readlines()
Q111 Read following Python code carefully and predict the Creation
correct output of the code
f=open("test.txt","r")
print(f.tell(),end="6")
f.seek(5)
print(f.tell())

(A) 605
(B) 506
(C) 065
(D) 560
Q112 What does the readline() method returns? Understanding
(A) str
(B) a list of lines
(C) list of single characters
(D) list of integers
Q113 How do you change the file position to an offset value Analysis
from the start?
(A) fp.seek(offset, 0)
(B) fp.seek(offset, 1)
(C) fp.seek(offset, 2)
(D) none of the mentioned
Q114 Which statement will return one line from a file (file Understanding
object is ‘f’) as string?
(A) f.readlines( )
(B) f.readline( )
(C) f.read( )
(D) f.line(1)
Q115 Which function is used to read data from Text File? Understanding
(A) read( )
(B) writelines( )
(C) pickle( )
(D) dump( )
Q116 The syntax of seek() is: file_object.seek(offset [, Analysis
reference_point])
What is reference_point indicate?
(A) reference_point indicates the starting position of
the file object
(B) reference_point indicates the ending position of
the file object
(C) reference_point indicates the current position of
the file object
(D) All of the above.
Q117 The syntax of seek() is:file_object.seek(offset [, Application
reference_point]) What all values can be given as a
reference point?
(A) 1
(B) 2
(C) 0
(D) All of the above
Q118 What will be the output of the following code snippet? Analysis
f = None
for i in range (5):
with open("myfile.txt", "w") as f:
if i > 2:
break
print (f.closed)
(A) Runtime Error
(B) True
(C) False
(D) Hello world
Q119 What happens if no arguments are passed to the seek Analysis
function?
(A) file position is set to the start of file
(B) file position is set to the end of file
(C) file position remains unchanged
(D) error
Q120 How do you change the file position to an offset value Application
from the current position?
(A) fp.seek(offset, 0)
(B) fp.seek(offset, 1)
(C) fp.seek(offset, 2)
(D) none of the mentioned
Q121 What are the file types in Python?
(A) Text File Understanding
(B) Binary File
(C) CSV File
(D) All of the above
Q122 What are the examples of Binary file in Python?
(A) .jpeg Understanding
(B) .gif
(C) .bmp
(D) All of the above
Q123 Which command is used to open a binary file in Python in Analysis
reading mode?
(A) F = open(“Data.dat”,”ab”)
(B) F = open(“Data.dat”,”wb”)
(C) F = open(“Data.dat, “rb”)
(D) All of the Above
Q124 Which command is used to open a binary file in Python in Analysis
append mode?
(A) F = open(“Data.dat”,”ab”)
(B) F = open(“Data.dat”,”wb”)
(C) F = open(“Data.dat, “rb”)
(D) None of the Above
Q125 Which operations can be performed in Python using Knowledge
“rb+” mode?
(A)Read
(B)Write
(C)Append
(D)Both Read and Write
Q126 Which operations can be performed in Python using Knowledge
“wb+” mode?
(A)Read
(B)Write
(C)Append
(D)Both Read and Write
Q127 Which operations can be performed in Python using Knowledge
“ab+” mode?
(A)Read
(B)Write
(C)Append
(D)Both Read and Write
Q128 Which function is used to close the contents of a binary Knowledge
file?
(A) read ( )
(B) write ( )
(C) close ( )
(D) None of these
Q129 When we open a Binary file in append mode , by default Understanding
new data can be added at the?
(A) Beginning of the file
(B) End of the file
(C) At the middle of the file
(D) All of the above
Q130 File object is also called: Knowledge
(A)read-handle
(B)file-handle
(C)data-Handle
(D) All of the above
Q131 In python binary file is treated as a : Understanding
(A)Sequence of bits
(B)Sequence of Bytes
(C)Sequence of numbers
(D)Sequence of characters

Q132 Which file mode is invalid? Knowledge


(A)ab
(B)rb+
(C)wb
(D)rw
Q133 Which file mode is valid? Knowledge
(A)b+
(B)rb+
(C)rw+
(D)rw
Q134. When we open a binary file in write mode the file pointer
is present at the:
(A)End of the file
(B)Beginning of the file
(C)Anywhere in between the file
(D)Second line of the file
Q135. What can be taken as a parameter in the open( ) function
of a binary file?
(A) File name
(B) Access mode
(C) Both of the above
(D) None of the above
Q136 A Binary file stores information in the form of Knowledge
__________ .
(A) A stream of bytes
(B) A stream of ASCII characters
(C) A stream of UNICODE characters
(D) All of the above
Q37 Which of the following file mode will refer to the Understanding
BINARY mode?
(A) binary
(B) b
(C) bin
(D) w
Q138 The process of converting the structure to a byte stream Knowledge
before writing to the file is known as ______.
(A) Pickling
(B) Unpickling
(C) Conversion
(D) Changing
Q139 Which of the following is not a correct statement for Evaluation
binary files?
(A) Easy for carrying data into buffer
(B) Much faster than other file systems
(C) Characters translation is not required
(D) Every line ends with new line character ‘\n’
Q140 Which of the following file mode open a file for reading Knowledge
and writing both in the binary file?
(A) r
(B) rb
(C) rb+
(D) rwb
Q141 Which of the following file mode open a file for reading Knowledge
and writing both in the binary file?
(A) wb
(B) wb+
(C) w+b
(D) B & C both
Q142 Which of the following file mode opens a file for append Knowledge
or read a binary file and moves the files pointer at the end
of the file if the file already exist otherwise create a new
file?
(A) a
(B) ab
(C) ab+
(D) a+
Q143 Which is not the valid mode for binary files? Evaluation
(A) r
(B) rb
(C) rb+
(D) ab+
Q144 Suresh wants to open the binary file student.dat in read Application
mode. He writes the following statement but he does not
know the mode. Help him to find the same.
F=open(‘student.dat’, ____)
(A) r
(B) rb
(C) wb
(D) w
Q145 In which file type, no delimiters are used for line and no Knowledge
translations occur?
(A) Text file
(B) Binary file
(C) CSV file
(D) All of the above
Q146 The _________ files are used to store large data such as Analysis
images, video files, audio files etc.
(A) Text
(B) Binary
(C) CSV
(D) None of the Above
Q147 Which type of the file executes faster? Analysis
(A) Text File
(B) CSV File
(C) Binary File
(D) Word File
Q148 Which of the following method is used to open a binary Evaluation
file?
(A) open( )
(B) run( )
(C) execute( )
(D) None of the above
Q149 Which of the following is / are arguments for open( ) Knowledge
method in a binary file?
(A) Path & file name
(B) Mode to open a binary file
(C) A & B Both
(D) Neither A Nor B
Q150 To close a binary file which of the following statement is Application
correct?
(A) <fileobj>.stop()
(B) <fileobj>.closebin()
(C) <fileobj>.stopbin()
(D) <fileobj>.close()
Q151 To open a file c:\scores.dat in binary for reading, we use
_____________ Application
A) infile = open(“c:\scores.txt”, “r”)
B) infile = open(“c:\\scores.dat”, “rb”)
C) infile = open(file = “c:\scores.txt”, “r”)
D) infile = open(file = “c:\\scores.txt”, “r”)

Q152 What is Binary File ? Knowledge


A) These files can not be read by humans directly.
B) No delimiter for a line
C) Processing of file is faster than text file
D) All

Q153 Steps to work with Binary File in Python import pickle Analysis
module. writing or appending data.
A) Open File in required mode (read, write or append).
B) Write statements to do operations like reading,
C) Close the binary file
D) All

Q154 Which function is used to write data in binary mode? Knowledge


A) write
B) writelines
C) pickle
D) dump

Q155 Which function is used to read data in binary mode? Knowledge


A) read
B) load
C) pickle
D) dump

Q156 Which of the following is not a correct statement for Analysis


binary files?
A) Easy for carrying data into buffer
B) Much faster than other file systems
C) Characters translation is not required
D) Every line ends with new line character ‘\n’

Q157 Which of the following file mode open a file for reading Knowledge
and writing both in the binary file?
A) w
B) wb+
C) wb
D) rwb
Q158 Ms. Suman is working on a binary file and wants to write Application
data from a list to a binary file. Consider list object as l1,
binary file suman_list.dat, and file object as f. Which of
the following can be the correct statement for her?
A) f = open(‘sum_list’,’wb’); pickle.dump(l1,f)
B) f = open(‘sum_list’,’rb’); l1=pickle.dump(f)
C) f = open(‘sum_list’,’wb’); pickle.load(l1,f)
D) f = open(‘sum_list’,’rb’); l1=pickle.load(f)
Q159 In which of the file mode existing data will be intact in Understanding
binary file?
A) ab
B) a
C) w
D) wb
Q160 Which one of the following is correct statement? Evaluation
A) import – pickle
B) pickle import
C) import pickle
D) All of the above
Q161 Dump method is used to Knowledge
A) Write in a text file
B) Write in a binary file
C) Read from text file
D) Read from binary file
Q162 Which module is needed to be imported to work with Analysis
binary file?
A) csv module
B) random module
C) binary module
D) pickle module
Q163 Which method is used to change the current file pointer Knowledge
position?
A) offset()
B) tell()
C) seek()
D) point()
Q164 In binary file data is stored in which format Understanding
A) Binary
B) Text
C) ASCII
D) UNICODE
Q165 Binary file has advantage over text file. Analysis
A) It occupies less memory
B) It is fast to work with binary file
C) Computer understands this data without any
conversion
D) All of the above
Sl.No Question: Learning Objective
Q166 The module, which can use to process binary file About basic library to
use for binary file
(A) json
(B) lxml
(C) pickle
(D) none of these
Q167 Correct statement to declare necessary library to process Knowledge about syntax
the records by directly access the audio data as python to use pickle
objects
(A) pickle import
(B) import pickle as pkd
(C) import audio
(D) audio import
Q168 The method used to serialise the python objects for Awareness about method
writing data in binary file of pickle module to write
data
(A) dump( )
(B) open( )
(C) write( )
(D) serialise( )
Q169 The statement to prepare the buffer in memory to The correct syntax of use
examine the contents of the binary file (‘data.dat’) of open( ) function to
read binary file
(A) f=open( “data.dat” , “r”)
(B) f=open( data.dat , “rb” ).
(C) f=open( data.dat, “r” )
(D) f=open( “data.dat” , “rb” )
Q170 The method used to unpickling the data from a binary file Awareness about the
method to load data from
(A) unpickle( )
binary file to process
(B) load( )
(C) deserialise( )
(D) read( )
Q171 What is wrong with the following code ? Awareness about that
write( ) on binary file
listvalues = [1, “Geetika”, ‘F’, 26]
requires bytes only.
fileobject = open( ‘mybinary.dat’ , ‘wb’ )
fileobject.write ( listvalues)
fileobject.close( )
(A) error in open mode of file
(B) error, pickle is essential to use write( )
(C) error in write( )
(D) No error
Q172 Let the file ‘abc.csv’ contains the following records in Awareness about that,
comma separated way processing csv file using
binary methods will not
1,Geetika,F,26
work without converting
2,Jeevan,M,24 the loaded binary data to
text format before further
Consider the following code
processing
fileobject = open( ‘abc.csv’ , ‘rb’ )
contents=fileobject.read( )
lst=contents.split( )
for rec in lst:
print(lst.split(‘,’)[1],end=’#’)
fileobject.close( )

Find the output of above code


(A) runtime error
(B) syntax error
(C) 1#2#
(D) Geetika#Jeevan#
Q173 Through python code, a file ‘data.dat’ need to be created Aware about correct
and store the following record opening mode to save the
binary data into file
[‘XIIA’,{‘no of students’:25, ‘average attendance’:26}]
, which is to be stored in memory in form of python list
as specified above.
Consider the following code:
import pickle
fileobject=open( ‘data.dat’, ‘_____’ ) #statement1
listvalues =[‘XIIA’,{‘no of students’:25, ‘average
attendance’:26}]
pickle.dump( listvalues, fileobject)
fileobject.close( )
Fill in the blanks for statement1
(A) rb
(B) w
(C) wb
(D) r
Q174 Which of the following functions can accept more than Know about parameters
one positional argument? of methods of pickle
module
(A) pickle.load( )
(B) pickle.dump( )
(C) pickle.loads( )
(D) None of these
Q175 The method of pickle module to get the data from the Know about methods of
binary file pickle module
(A) dumps( )
(B) dump( )
(C) load( )
(D) loads( )
Q176 In data handling through pickle module, seek( ) on working of seek()
fileobject function in context of
pickle module
(A) can place file position on specific record
(B) not useful, except placing the file position at start or
at end.
(C) gets the file position
(D) finds the length of file
Q177 pickle.dump( ) on binary file opened in ‘ab’ mode Aware about work of
append mode in context
(A) add pickled python object at the end of file
of pickle
(B) insert pickled python object at position marked ‘a’
(C) store the given python object as a string
(D) none of these
Q178 The process of transforming data or an object in memory Aware about
(RAM) to a byte stream. Serialisation process
done by pickle module
(A) Byte
(B) Read
(C Serialisation
(D) Unpickle
Q179 Find output of following code Understand code,
involving pickle module
import pickle
fileobject=open(‘data.dat’ , ‘wb’)
L=[3,4,5,9]
pickle.dump(L, fileobject)
fileobject.close( )
fileobject=open(‘data.dat’ , ‘rb’)
print( pickle.load(fileobject)[1]*2)
fileobject.close( )
(A) [3, 4, 5, 9 ]
(B) [6,8,10,18].
(C) 6
(D) 8
Q180 Find output of the following code: Understand code,
involving pickle module
import pickle
def storeData():
# initializing data to be stored in db
Robert = {'name' : ‘Robert Dsouza’, 'age' : 25, 'pay' :
25000}
Rima = {'name' : ‘Rima Sood‘ ,'age' : 43, 'pay' : 45000}
db = {}
db[' Robert'] = Robert
db['Rima'] = Rima
dbfile = open('data.dat', 'ab')
pickle.dump(db, dbfile)
dbfile.close()

def loadData():
dbfile = open('examplePickle', 'rb')
db = pickle.load(dbfile)
p=0
for keys in db:
p += db[keys][‘pay’]
print(p)
dbfile.close()

storeData()
loadData()

(A) 45000
(B) 70000
(C) 25000
(D) none of these
Q181. Which module is used to store data into python objects Understanding
with their structure?
(A) pickle
(B) binary files
(C) unpickle
(D) None of these
Q182 Which one of the following is the correct statement? Understanding
(A) pickle import
(B) import – pickle
(C) import pickle
(D) None of the above
Q183 Which function is use for reading data from a binary file? Application
(A) load()
(B) read()
(C) dump()
(D) None of the above
Q184 Which function is use for writing data in binary file? Creation
(A) load()
(B) write()
(C) dump()
(D) None of the above
Q185 _______ the process in which an object converts into a Creation
byte stream
(A) unpickling
(B) pickling
(C) (A) and (B)
(D) None of the above
Q186 Serialization in binary file is also called __________ Creation
(A) Unpickling
(B) Pickling
(C) Both (A) and (B)
(D) None of the above
Q187 ________ function places the file pointer at the specified Knowledge
position by in an open file.
(A) tell()
(B) seek()
(C) both A and B
(D) None of the above
Q188. _______ function return the current position of the file Knowledge
pointer.
(A) tell()
(B) seek()
(C) both A and B
(D) None of the above
Q189 Fill in the blank: Understanding,
import pickle Knowledge,
f=open("data.dat",'rb') Application, Evaluation
d=_____________________.load(f) # Statement1
f.close()

(A) unpickle
(B) pickling
(C) pickle
(D) pick
Q190 Which of the following function takes two arguments? Knowledge
a) load()
b) dump()
c) Both of the above
d) None of the above
Q191 .pdf and .doc are examples of ________ files. Application
(A) Text
(B) Binary
(C) CSV
(D) None of the above
Q192 The syntax of seek() is : file_object.seek(offset Understanding
[,reference_point]). What all values can be given as a
reference point?
(A) 1
(B) 2
(C) 0
(D) All of the above
Q193 f.seek(10,0) will move 10 bytes forward from _______. Application
(A) beginning
(B) End
(C) Current
(D) None of the above
Q194 Which statement will move file pointer 10 bytes Understanding
backward from end position.
(A) F.seek(-10,2)
(B) F.seek(10,2)
(C) F.seek(-10,1)
(D) None of the above
Q195 Aman opened the file “myfile.dat” by using the following Evaluation
syntax. His friend told him few advantages of the given
syntax. Help him to identify the correct advantage.
with open(“myfile.dat”, ‘ab+”) as fobj:
(A) In case the user forgets to close the file explicitly
the file will closed automatically
(B) File handle will always be present in the
beginning of the file even in append mode.
(C) File will be processed faster
(D) None of the above.
Q196 Which of the following method is used to clear the Analysis
buffer?
(A) clear()
(B) buffer()
(C) flush()
(D) clean()
Q197 Write the output of the following: Understanding,
f=open(“t.dat”, “rb”) Knowledge,
print(f.tell()) Application, Evaluation
(A) 1
(B) 2
(C) -1
(D) 0
Q198 Write the output of the following: Understanding,
f=open(“t.dat”, “r”) Knowledge,
print(f.tell(), end=”6”) Application, Evaluation
f.seek(5)
print(f.tell())
(A) 165
(B) 650
(C) 065
(D) 506
S.No Question Learning Objective
Q199 Which mode create new file if the file does not exist? Knowledge
a) Write mode
b) Append mode
c) Both a & b
d) None of the above
Q200 seek() function is used to _____ Understanding
a) Positions the file object at the specified location.
b) It returns the current position of the file object
c) It writes the data in binary file
d) None of these
Q201 Which function is used to read data from Binary File? Knowledge
a) read()
b) load()
c) pickle()
d) dump()
Q202 Which symbol is used for append mode in Binary file? Understanding
a) a
b) a+
c) ab
d) None
Q203 Which function is used to write data in Binary File? Knowledge
a) read()
b) load()
c) pickle()
d) dump()
Q204 Fill in the blank Analysis
import pickle
file=open("data.dat",'rb')
d=_____________________.load(f)
f.close()
a) pick
b) pickling
c) file
d) pickle
Q205 ____________________ module is used for serializing Understanding
and de-serializing any Python object structure.

a) pickle
b) math
c) unpickle
d) random

Q206 Which of the following function takes two arguments? Understanding


a) load()
b) dump()
c) Both of the above
d) None of the above
Q207 Almost all the files in our computer stored as Knowledge
_______ file.
a) Text
b) Binary
c) CSV
d) None of the above
Q208 Read the code given below and answer the question: Analysis
import pickle
Fi=open("main.dat","wb")
pickle.dump("bye",Fi)
Fi.close()
If the file main.txt contains Good before execution, what
will be the content of the file after execution.
a) Good Bye
b) Bye
c) Nothing
d) Byed
Q209 Which of the following is not true about binary files? Understanding
a) Binary files are store in terms of bytes
b) When you open binary file in text editor will show
garbage values
c) Binary files represent ASCII value of characters
d) All of the above
Q210 In order to read the content from the Binary file, we can Understanding
open file in
a) “rb” mode
b) “rb+” mode
c) “wb+” mode
d) All of the above
Q211 Which of the following method is used to clear the Knowledge
buffer?
a) clear()
b) buffer()
c) close()
d) flush()
Q212 Fill in the blank in the given code : Analysis
import pickle
f = open("data.dat", "rb")
l = pickle._______(f)
print(l)
f.close()
a) dump()
b) load()
c) write()
d) read()
Q213 Fill in the blank in the given code : Analysis
import pickle
f = open("data.dat", "wb")
L = [1, 2, 3]
pickle._______
f.close()
a) dump(L,f)
b) dump(f,L)
c) load(L,f)
d) load(f,L
Q214 Which of the following module is provided by Python to Understanding
do several operations on the CSV files?
(A) os
(B) xls
(C) csv
(D) py
Q215 Which of the following is tasks cannot be done or Understanding
difficult with CSV module?
(A) Storing data in tabular form
(B) Finding data uniquly
(C) Saving data permanently
(D) All of these
Q216. The writer() function of csv module has how many Creation
mandatory parameters?
(A) 4
(B) 3
(C) 2
(D) 1
Q217 Which of these is not relevant to csv file? Understanding
(A) Text file
(B) Binary file
(C) Easily openable in text editor
(D) None of the above
Q218 You are having myfile.csv file on c drive. You want to Application
access it in python, how can you do this?
(A) source=”c:\\myfile.csv”
data = pd.read_csv(source)
(B) source=”c:\\myfile.csv”
data = pd.reads_csv(source)
(C) source=”c:\\myfile.csv”
data = pd.reader(source)
(D) None of the above
Q219 Which is the correct way to import a csv module? Application
(A) import csv
(B) from csv import *
(C) None of the above
(D) Both A & B
Q220 In regards to separated value in files such as .csv and .tsv, Understanding
what is the delimiter?
(A) Any character such as the comma (,) or tab ;) used to
separate the column data.
(B) Delimiters are not used
(C) Only the comma (,) character is used in the file
(D) Any character such as the comma (,) or tab ;) used to
separate the row data.
Q221 In separated value files such as .csv, what does the first Understanding
row in the file
typically contain?
(A) The author name
(B) Notes about the data
(C) Column Heading
(D) The source of the data

Q222 Which of the following object you get after reading CSV Understanding
file?
(A) Character Vector
(B) Comma Vector
(C) Panel
(D) DataFrame
Q223 Which of the following is a function of csv module? Evaluation
(A) writerrow()
(B) reading()
(C) writing()
(D) readline()
Q224 To open a file c:\myscores.csv for reading, we use Application
_______ command.
(A) infile = open(“c:\myscore.csv”, “r”)
(B) infile = open(“c:\\myscore.csv”, “r”)
(C) infile = open(file = “c:\myscore.csv”, “r”)
(D) infile = open(file = “c:\\myscore.csv”, “r”)
Q225 Which of the following statement(s) are true for csv files? Understanding
(A) Existing file is overwritten with the new file if
already exist
(B) If the file does not exist, a new file is created for
writing purpose
(C) When you open a file for reading, if the file does not
exist, an error occurs
(D) All of the above
Q226 To read the entire content of the CSV file as a nested list Application
from a file object infile, we use __________ command.
(A) infile.read()
(B) infile.reader()
(C) csv.reader(infile)
(D) infile.readlines()
Q227 Which of the following is not a valid mode to open CSV Creation
file?
(A) a
(B) w
(C) r
(D) ab
Q228 The CSV files are popular because they are Understanding
(A) capable of storing large amount of data
(B) easier to create
(C) preferred export and import format for databases and
spread sheets
(D) All the above
Q229 When iterating over an object returned from csv.reader(), Application
what is returned with each iteration?
For example, given the following code block that assumes
csv_reader is an object returned from csv.reader(), what
would be printed to the console with each iteration?
for item in csv_reader:
print(i)
(A) The individual value data that is separated by the
delimiter
(B) The row data as a list
(C) The column data as a list
(D) The full line of the file as a string
Q230 Which of the following parameter needs to be added with Application
open function to avoid blank row followed by each row in
the CSV file?
(A) quotechar
(B) quoting
(C) newline
(D) skiprow

Q231 In separated value files such as .csv, what does the first Understanding
row in the file typically contain?
(A) The author of the table data
(B) The column names of the data
(C) The source of the data
(D) Notes about the table data
Q232 A _________ is a file format which stores records Knowledge
separated by comma.
(A) .jpg
(B) .pdf
(C) .csv
(D) None of the above
Q233 Which of the following Python statement is used to read Understanding
the entire content of the CSV file as a nested list from a
file object infile?
(A) infile.read()
(B) infile.reader()
(C) csv.reader(infile)
(D) infile.readlines()
Q234 What is the full form of CSV? Knowledge
(A) Comma Separated Values
(B) Comma Separated Value
(C) Comma Separated Variables
(D) Comma Separate Values
Q235 EOL character used in windows operating system in CSV Knowledge
files is
(A) \r\n
(B) \n
(C) \r
(D) \0
Q236 _________ is the default delimiter character of a CSV Knowledge
file.
(A) : (colon)
(B) \t (tab)
(C) , (comma)
(D) ; (semi-colon)
Q237 A CSV file marks.csv is stored in the storage device. Application
Identify the correct option out of the following options to
open the file in read mode.
i. myfile = open('marks.csv','r')
ii. myfile = open('marks.csv','w')
iii. myfile = open('marks.csv','rb')
iv. myfile = open('marks.csv')

(A) only i
(B) both i and iv
(C) both iii and iv
(D) both i and iii
Q238 Which of the following is a function of the csv module? Knowledge
(A) readline()
(B) reader()
(C) read()
(D) readrow()
Q239 What is the output of the following program? Application
import csv
d=csv.reader(open('city.csv'))
for row in d:
print(row)
break
If the file called city.csv contains the following details
Bhubaneshwar, Kolkata
Guwahati, Silchar
(A) Guwahati, Silchar
(B) Bhubaneshwar, Kolkata
(C) Bhubaneshwar, Kolkata
Guwahati, Silchar
(D) Bhubaneshwar
Guwahati
Q240 The CSV files are _______ files. Knowledge
(A) Python
(B) Binary
(C) Data
(D) Text
Q241 The writer() function has how many mandatory Understanding
parameters?
(A) 1
(B) 2
(C) 3
(D) 4
Q242 Vikas wants to separate the values in a csv file by a # Understanding
sign. Suggest to him a pair of function and parameter to
use it.
(A) open,quotechar
(B) writer,quotechar
(C) open,delimiter
(D) writer, delimiter
Q243 Which of the following option is correct? Understanding
i. if we try to read a csv file that does not exist, an
error occurs.
ii. if we try to read a csv file that does not exist, the
file gets created.
iii. if we try to write on a csv file that does not exist,
an error occurs.
iv. if we try to write on a csv file that does not exist,
the file gets Created.

(A) only i
(B) only iv
(C) both i and ii
(D) both i and iv

ANSWERS

Question No Answer
Q1 (D) No Output
Q2 (C) ..\First Term\Result1.xlsx
(D) In ‘a+’ mode, both reading and writing operations can take
Q3 place and new data is appended to the end of the existing file.
Q4 (B) disp = fileobj.readlines()
Q5 (C) Both (ii) and (iii)
Q6 (C) Binary file
Q7 (C) tell()
(C) It will place the pointer at 25 bytes from the beginning of the
Q8 file.
Q9 (A) dt = f.readlines();print(dt[3])
Q10 (A) reader(), writer()
Q11 (D) All of the above
Q12 (B) slowly but steadily
Q13 (C) 9
Q14 (A) write()
(B) In r+ mode, the pointer is initially placed at the beginning of
Q15 the file and for w+, the pointer is placed at the end.
Q16 C
Q17 B
Q18 B
Q19 A
Q20 D
Q21 B
Q22 c
Q23 B
Q24 C
Q25 B
Q26 B
Q27 D
Q28 B
Q29 A
Q30 A
(C) f = open(“file.txt”,’w’)
Q31
Q32 (A) with open(“file.txt”, “a”) as f :
Q33 (D) b+
Q34 (B) f.close()
Q35 (C) writelines()
Q36 (A) write()
Q37 (C) Both of the above
Q38 (A) r
Q39 (B) w
Q40 (C) Both of the above
Q41 (C) Both of the above
(B) In both modes file pointer for existing file sets to beginning of
Q42 file.
Q43 (D) File does not exist
(B) Both strings of list lines will be written in the same line in the
Q44 file ‘readme.txt’.
(A) Both strings of list lines will be written in two different lines
Q45 in the file ‘readme.txt’.
D
Q46
Q47 C
Q48 D
Q49 A
Q50 D
Q51 A
Q52 C
Q53 B
Q54 B
Q55 C
Q56 D
Q57 D
Q58 A
Q59 C
Q60 A
Q61 D

Q62 D

Q63 C

Q64 B

Q65 D

Q66 A

Q67 A

Q68 D

Q69 A

Q70 A

Q71 A

Q72 A

Q73 A
C
Q74
A
Q75
Q76 (b) fobj.read()
Q77 (a) fp.seek(offset, 0)
Q78 (b) fp.tell()
Q79 (d) results in an error
Q80 (a) readline()
Q81 a. seek()
Q82 a) sets the file‟s current position at the offset
Q83 a) fp.seek(offset, 0)
Q84 a. 0
Q85 a) fp.seek(offset, 0)
Q86 d) error
Q87 b. List
Q88 b. read(n)
Q89 a. File-
Q90 c. FileHandling
Q91 A
Q92 C
Q93 B
Q94 A
Q95 B
Q96 D
Q97 A
Q98 D
Q99 A
Q100 A
Q101 D
Q102 D
Q103 D
Q104 B
Q105 A
Q106 D
Q107 B
Q108 C
Q109 A
Q110 B
Q111 C
Q112 A
Q113 A
Q114 B
Q115 A
Q116 D
Q117 D
Q118 B
Q119 D
Q120 B
D
Q121
Q122 D
Q123 C
Q124 A
Q125 D
Q126 D
Q127 D
Q128 C
Q129 B
Q130 B
Q131 B
Q132 D
Q133 B
Q134 B
Q135 C
Q136 (A) A stream of bytes
Q137 (B) b
Q138 (A) Pickling
Q139 (D) Every line ends with new line character ‘\n’
Q140 (C) rb+
Q141 (D) B & C both
Q142 (C) ab+
Q143 (A) r
Q144 (B) rb
Q145 (B) Binary file
Q146 (B) Binary
Q147 (C) Binary File
Q148 (A) open( )
Q149 (C) A & B Both
Q150 (D) <fileobj>.close()
Q151 B
Q152 D
Q153 D
Q154 D
Q155 B
Q156 D
Q157 B
Q158 A
Q159 A
Q160 C
Q161 B
Q162 D
Q163 C
Q164 A
Q165 D
C
Q166
B
Q167
A
Q168
D
Q169
B
Q170
C
Q171
A
Q172
C
Q173
B
Q174
C
Q175
B
Q176
A
Q177
C
Q178
D
Q179
B
Q180
Q181 A
Q182 C
Q183 A
Q184 C
Q185 B
Q186 B
Q187 B
Q188 A
Q189 C
Q190 B
Q191 B
Q192 D
Q193 A
Q194 A
Q195 A
Q196 C
Q197 D
Q198 C
Q199 C
Q200 A
Q201 B
Q202 C
Q203 D
Q204 D
Q205 A
Q206 B
Q207 B
Q208 B
Q209 C
Q210 D
Q211 D
Q212 B
Q213 A
Q214 (C) csv
Q215 (B) Finding data uniquly
Q216 (D) 1
Q217 (B) Binary file
(A) source=”c:\\myfile.csv”
Q218 data = pd.read_csv(source)
Q219 (D) Both A & B
(A) Any character such as the comma (,) or tab ;) used to separate
Q220 the column data
Q221 (C) Column Heading
Q222 (D) DataFrame
Q223 (A) writerrow()
Q224 (B) infile = open(“c:\\myscore.csv”, “r”)
Q225 (D) All of the above
Q226 (C) csv.reader(infile)
Q227 (D) ab
Q228 (D) All the above
Q229 c) The column data as a list

Q230 c) newline

Q231 b) The column names of the data

Q232 c) .csv

Q233 c) csv.reader(infile)
Q234 a) Comma Separated Values

Q235 a) \r\n

Q236 c) , (comma)

Q237 b) both i and iv

Q238 b) reader()

Q239 b) Bhubaneshwar, Kolkata

Q240 d) text

Q241 a) 1

Q242 d) writer, delimiter

Q243 d) both I and iv

Name of the vetter- KAMAL KANT GUPTA

Name of the KV- KV 2 KANCHRAPARA

Region- KOLKATA

Mobile No- 9493887480

E-mail ID - kamalkant.kv@gmail.com
Name of the Chapter- DATA FILE HANDLING

Question Question Content Learning Objective(if


No Provided)
Q1. Assertion: It is not necessary to always create the file in Knowledge
the same default folder where Python has been installed.
Reason: In binary file, there is no delimiter for a line. (A)
Both Assertion and reason are true and reason is correct
explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q2. Assertion: The relative paths are relative to current Knowledge
working directory.
Reason: The relative path for a file always remains same
even after changing the directory.
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.

Q3. Assertion: When you open a file for writing, if the file Understanding
does not exist, an error occurs.
Reason: When you open a file for writing, if the file
exists, the existing file is overwritten with the new file.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.

Q4. Assertion: The offset argument to seek() method indicates Understanding


the number of bytes to be moved.

Reason: If the offset value is set to 2, beginning of the


file would be taken as seek position
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.

Q5. Assertion: Every record in a CSV file is stored in reader Knowledge


object in the form of a list.

Reason: writerow() method allows us to write a list of


fields to the CSV file.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q6. Assertion (A): A file is a bunch of bytes.
Reason(R): Byte is a unit of memory
A. Both Assertion and reason are true and reason
is correct explanation of assertion.
B. Assertion and reason both are true but reason
is not the correct explanation of assertion.
C. Assertion is true, reason is false.
D. Assertion is false, reason is true.

Q7. Assertion (A): The The CSV File is delimited File.


Reason(R): Only Comma (,) can be use as delimiter in
CSV file.
A. Both Assertion and reason are true and reason
is correct explanation of assertion.
B. Assertion and reason both are true but reason
is not the correct explanation of assertion.
C. Assertion is true, reason is false.
D. Assertion is false, reason is true.

Q8. Assertion (A): The full name of a file or a directory is


called Absolute path.
Reason(R): relative path is relative to current working
directory.
A. Both Assertion and reason are true and reason
is correct explanation of assertion.
B. Assertion and reason both are true but reason
is not the correct explanation of assertion.
C. Assertion is true, reason is false.
D. Assertion is false, reason is true.

Q9. Assertion (A): EOL character is a line terminator in text


file.
Reason(R): By default, EOL Character is the new line
character in Text File.
A. Both Assertion and reason are true and reason
is correct explanation of assertion.
B. Assertion and reason both are true but reason
is not the correct explanation of assertion.
C. Assertion is true, reason is false.
D. Assertion is false, reason is true.

Q10. Assertion (A): File created by notepad cannot be access in


python program.
Reason(R): A text file can be created by Notepad.
A. Both Assertion and reason are true and reason
is correct explanation of assertion.
B. Assertion and reason both are true but reason
is not the correct explanation of assertion.
C. Assertion is true, reason is false.
D. Assertion is false, reason is true.

Q11. Assertion: File can be opened in append mode. KNOWLEDGE AND


Reason: In append mode file content does not get UNDERSTANDING
overwritten and user can append the content after existing
content.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q12. Assertion: It's mandatory to mention file mode while KNOWLEDGE AND
opening a file for reading. UNDERSTANDING
Reason: By default, the file opens in read mode.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q13. Assertion: File can be opened using open() function and KNOWLEDGE AND
“with open() as f:” syntax. UNDERSTANDING
Reason: Once a file is opened it can’t be closed.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q14. Assertion: There is no need to close a file explicitly if APPLICATION
opened using “with open() as f:” syntax. (where f is file
stream object)
Reason: file gets closed using syntax f.close() where f is
a file stream object.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q15. Assertion: With the code given below a user can write ANALYSIS,
multiple lines one by one into a text file ‘readme.txt’ EVALUATION AND
lines = ['This is line 1', 'This is line 2'] CREATION
with open('readme.txt', 'w') as f:
for line in lines:
f.write(line+’\n’)
Reason: As there is no error in code and as the write()
method only writes a single line at a time by appending
‘\n’ to each string of list lines.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q16. Assertion: Text File in Python by default open in reading
mode. Creation
Reason: When open a file in reading mode, file must be
exits.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q17. Assertion: Every File maintains a file pointer which tells Creation
the current position in the file where writing or reading
will takes place.
Reason: file pointer advances by the specified number of
bytes.
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q18. Assertion: The function readline( ) reads a line at a time. Analysis
Reason: The readline( ) function can be used to read the
entire file.
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q19. Assertion: User can open a file into read and write mode Creaton
at the same time..
Reason: Python provides function “r+” and “w+’ to open
a file in read and write mode at the same time.
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q20. Assertion: New content can be added to the existing file. Understanding
Reason: The mode “a” is used for append mode.
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q21. def count H (): UNDERSTANDING
f = open (“para.txt” , “r” ) KNOWLEDGE
lines =0 ANALYSIS
l=f. readlines () EVALUATION
for i in L:
if i [0]== ‘H’:
lines +=1
print (“No. of lines are: “ , lines)
Assertion: In above program file mode is read only.
Reason: File must exist already ,otherwise Python raises
I/O error
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q22. observe the following code UNDERSTANDING
f1=open("mydata","a") KNOWLEDGE
______#blank1 ANALYSIS
f1.close() EVALUATION

Assertion: In above program file close () function is


important.
Reason: File automatically closed ,otherwise Python
raises I/O error
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q23. if file “try.txt” does not exist? UNDERSTANDING
f = open(“try.txt”) KNOWLEDGE
ANALYSIS
Assertion: Syntax is incomplete EVALUATION
Reason: Python raises FileNotFoundError
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q24. What is the purpose of ‘r’ as prefix in the given UNDERSTANDING
statement? KNOWLEDGE
f = open(r “d:\color\flower.txt”) ANALYSIS
Assertion: The purpose of ‘r’ as prefix in the given EVALUATION
statement is to make it raw string .

Reason: Python raises FileNotFoundError


(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q25. f=None UNDERSTANDING
for i in range(5): KNOWLEDGE
with open("data.txt","w") as f: ANALYSIS
if(i>2): EVALUATION
break
print(f.closed)

Assertion: Here ‘w’refers the text file in write only

Reason: If the file does not exist, file is created


(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.

Q26. Assertion: readline() function will read one line from the Knowledge
file. Understanding
Analysis
Reason: readlines() function will read all the lines from
the files.

(A) Both Assertion and reason are true and reason is


correct
explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q27. Assertion: Knowledge
To read twelve characters from a file object fin we use Understanding
fin.read(). Analysis

Reason:
We can use readline( ) function which can read one line at
a time from the file.

(A) Both Assertion and reason are true and reason is


correct
explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q28. Knowledge
Assertion: Understanding
>>> myobj=open("myfile.txt", 'r') Analysis
>>> print(myobj.readlines())
This code will read all the lines from the file.
Reason: readlines() function reads all the lines from a text
file.

(A) Both Assertion and reason are true and reason is


correct
explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q29. Assertion: Knowledge
In code given below, the file object will move 10 bytes Understanding
file_object.seek(10, 0) Analysis

Reason:
Seek() function with negative offset only works when file
is opened in binary mode.

(A) Both Assertion and reason are true and reason is


correct
explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q30. Assertion: Knowledge
Ravi opened the file myfile.txt in append mode. In this Understanding
file the file object/file handle will be at the end of the file. Analysis

Reason: ‘w’ (mode write) mode is default file mode.

(A) Both Assertion and reason are true and reason is


correct
explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q31 Assertion: Text files stores information in ASCII and Knowledge &
Unicode characters understanding
Reason: In text files there is no delimiter for a line
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q32 Assertion: A file created using the statement: Knowledge &
r = open( “text” ) is a text file understanding
Reason: Since the name of the file in open( ) is ‘text’ so
the statement creates a text file
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q33 Assertion: f=open(‘abc.txt’,’r’) Understanding &
L=len(f.read()) application
Print(f.read())
the above code will return No output
Reason: first read() statement put the file pointer at the
end of file, so next f.read() will
Return nothing
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q34 Assertion: myfile = Knowledge &
open("Myfile.txt") understanding
data_rec =
myfile.readlines()

myfile.close()
in the above code, data type of data_rec is a
list class.
Reason: Myfile.txt is a text file so it contains only list of
text lines.
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q35 Assertion: f=open(‘story.txt’,’r+’) Knowledge and
Above statement will create a new file, it it is understanding
not exist.
Reason: when we open a file in write mode, it will create
a new file with same name.
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q36 Read the following statements and give the answer Analysis
Assertion: readline() read the files line by line
Reason: Without realine() lines from the file cannot be read

(A) Both Assertion and reason are true and reason is


correct explanation of assertion
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion
(C) Assertion is true, reason is false
(D) Assertion is false, reason is true
Q37 Read the following statements and give the answer Analysis
A (Assertion): read () function reads the entire content
of the text file at one go
R (Reason): It returns content as string

(A) Both Assertion and reason are true and reason is


correct explanation of assertion
(B)Assertion and reason both are true but reason is not
the correct explanation of assertion
(C)Assertion is true, reason is false
(D)Assertion is false, reason is true

Q38 Read the following statements and give the answer Analysis
Assertion: seek (5,0) moves cursor after 5 bytes
Reason: It helps to read entire content after 5
characters

(A) Both Assertion and reason are true and reason is


correct explanation of assertion
(B)Assertion and reason both are true but reason is not
the correct explanation of assertion
(C)Assertion is true, reason is false
(D)Assertion is false, reason is true

Q39. Read the following statements and give the answer Analysis
Assertion: readline(5) reads 5 characters from the
line.
Reason: next readline() read the same line.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion
(B)Assertion and reason both are true but reason is not
the correct explanation of assertion
(C)Assertion is true, reason is false
(D)Assertion is false, reason is true

Q40. Read the following statements and give the answer Analysis
Assertion: readlines() returns one line at a time
Reason: readlines() helps in counting number of lines
of the text file

(A) Both Assertion and reason are true and reason is


correct explanation of assertion
(B)Assertion and reason both are true but reason is not
the correct explanation of assertion
(C)Assertion is true, reason is false
(D)Assertion is false, reason is true

Q41. Assertion: While opening a binary file in read only


mode ‘rb’ , the file must exist. Analysis
Reason: Python raises I/O error if the file is unavailable
while opening file in read only mode
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q42. Assertion: While opening a binary file in write only Analysis
mode ‘wb’ , if the file doesn’t exist ,file is created.
Reason: If the file exists,Python python will overwrite
the current file in write only mode.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q43. Assertion: While opening a binary file in append mode Analysis
‘ab’ , if the file exists ,the data in the file is retained and
the new data is written at the end of the file.
Reason: If the file does not exist ,Python will create a
new file in ‘ab ‘ mode.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q44. Assertion: While opening a binary file in read only Analysis
mode ‘rb+’ , the file must exist.
Reason: Python raises I/O error if the file is unavailable
while opening file in ‘rb+’ mode.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q45. Assertion: While opening a binary file in write and read Analysis
mode ‘wb+’ , if the file doesn’t exist ,file is created.
Reason: If the file exists,Python python will overwrite
the current file in ‘wb+’ mode.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q46. Assertion: There is no line delimeter in binary files. Knowledge
Reason: Binary file stores data line by line.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q47. Assertion: open() method uses the ‘path & filename’ with Understanding
‘mode of opening’ a binary file.
Reason: There are three modes to open a file in python
that are read, write and append.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q48. Assertion: Access mode ‘ab’ opens a file for appending Application
data.
Reason: The file pointer is at the end of the file in the file
exists.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q49. Assertion: Binary file stores data in a format understand Analysis
easily by the computer hardware.
Reason: Computer hardware only understand the binary
language.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q50. Assertion: ‘rb+’ mode opens a binary file in read only Evaluation
mode.
Reason: The file pointer in ‘rb+’ mode exist at the
beginning of file.

(A) Both Assertion and reason are true and reason is


correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q51 Assertion (A) : By default file is opened in read mode.
Reasoning (R): while opening a file if we are not Analysis
specifying the mode then default it will open in read
mode
A) Only assertion is true
B) Assertion and reason does not match
C) Both assertion and reasoning is false
D) Both assertion and reasoning is true
Q52 Assertion (A) : we need to import csv module to read and Analysis
write in a binary file
Reasoning (R): writerow() function is defined in pickle
module.
A) Only assertion is true
B) Assertion and reason does not match
C) Both assertion and reasoning is false
D) Both assertion and reasoning is true
Q53 Assertion (A) : Processing of binary file is faster than Analysis
text file.
Reasoning (R): In text file is terminated with a special
character known as EOL character
A) Only assertion is true
B) Assertion and reason does not match
C) Both assertion and reasoning is false
D) Both assertion and reasoning is true
Q54 Assertion (A) : A file object is needed to reference to a Analysis
file on the disk.
Reasoning (R): With the help of this file we can perform
different task on file.
A) Only assertion is true
B) Assertion and reason does not match
C) Both assertion and reasoning is false
D) Both assertion and reasoning is true
Q55 Assertion (A) : Closing of all the opened file is done in Analysis
when no reference is needed for the opened file.
Reasoning (R): Closing of file breaks the link of file
object and the file on the disk.
A) Only assertion is true
B) Assertion and reason does not match
C) Both assertion and reasoning is false
D) Both assertion and reasoning is true

Q56 Assertion: pickle module can save python objects into pickling process
binary file
Reason: pickling process converts python objects into
byte stream
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q57 Assertion: pickle.load( ) deserialise the python object unpickling process
Reason: Deserialise object process involves conversion of
python object into string
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q58 Assertion: “import pickle” statement is required to use use of pickle
pickle in python program
Reason: “pip install pickle” command is required to
install pickle in python
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q59 Assertion: “L=[3,4] ; f=open(‘L1.dat’,’wb’); Serialisation Process
pickle.dump(L,f); f.close( ) “ => Serialise the [3,4] as
byte squence into file L1.dat
Reason: pickle.dum( A , B) => Serialise the Python
object A as a byte stream onto the file using fileobject B
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q60 Assertion: d={‘a’:12, ‘b’:10}; f=open(‘data.dat’, ‘wb’); Difference between
f.write( d ); f.close( ) => Python object d is serialised Writing memory block
onto file using file object f and Serialisation of
object
Reason: d={‘a’:12, ‘b’:10}; f=open(‘data.dat’, ‘wb’);
pickle.dump( d, f); f.close( ) => Python object d is
serialised onto file using file object f
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q61 Assertion: CSV is a kind of plain text file Understanding
Reason: It can be opened in all type of programs
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q62 Assertion: First use open() method to read data from file Creation
Reason: File File object is required to read data with the
help of csv.reader object/method
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q63 Assertion: We should use with() statement to write csv Application
related statement
Reason: with() statement at end releases all the resources
automatically without using close()
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q64 Assertion:CSV is best suitable to open in text editor Understanding
Reason: Most of the files can be opened in text editor
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q65 Assertion:close() method must be called as last statement Evaluation
related to csv file object
Reason: As it releases the assigned resources
(A) Both Assertion and reason are true and reason is
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q66.. Assertion: While writing data to csv file, we set the value Application
of parameter newline to "" in the open() function to
prevent blank rows.
Reason: EOL translation is suppressed by using
newline="".
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q67. Assertion: The CSV module in Python’s standard library Knowledge
presents methods to perform read/write operations on
CSV files.
Reasoning: To write data to a CSV file, we can use
built-in function writer().
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q68. Assertion: To open a CSV file employee.csv in write Understanding
mode, we can give python statement as follows:
fh=open('employee.csv’)
Reasoning: If we try to write on a csv file that does not
exist, the file gets Created
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q69. Assertion: We can open a CSV file in the same way as a Understanding
text file for reading and writing data.
Reason: A CSV file is a text file that uses a delimiter to
separate values.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.
Q70. Assertion: To specify a different delimiter while writing Application
into a csv file, delimiter argument is used with
csv.writer().
Reason: The CSV file can only take a comma as a
delimiter.
(A) Both Assertion and reason are true and reason is the
correct explanation of assertion.
(B) Assertion and reason both are true but reason is not
the correct explanation of assertion.
(C) Assertion is true, reason is false.
(D) Assertion is false, reason is true.

ANSWER

Question No Answer
Q1. (D) Assertion is false, reason is true.
Q2. (C) Assertion is true, reason is false.
Q3. (D) Assertion is false, reason is true.
Q4. (C) Assertion is true, reason is false
Q5. (B) Assertion and reason both are true but reason is not the correct
explanation of assertion.
Q6. A

Q7. C

Q8. B
Q9. A

Q10. D

Q11. (A) Both Assertion and reason are true and reason is the correct
explanation of assertion.
Q12. (D) Assertion is false, reason is true.
Q13. (C) Assertion is true, reason is false
Q14. (B) Assertion and reason both are true but reason is not the correct
explanation of assertion.
Q15. (A) Both Assertion and reason are true and reason is the correct
explanation of assertion.
Q16. A

Q17. A
Q18. B
Q19. A
Q20. A
Q21. A
Q22. C

Q23. A

Q24. C

Q25. A

Q26. (B) Assertion and reason both are true but reason is not the correct
explanation of assertion.
Q27. (D) Assertion is false, reason is true.
Q28. (A) Both Assertion and reason are true and reason is correct
explanation of assertion.
Q29. (B) Assertion and reason both are true but reason is not the correct
explanation of assertion.
Q30. (C) Assertion is true, reason is false.

Q31 C
Q32 C
Q33 A
Q34 B
Q35 D
Q36 C
Q37 B
Q38 A
Q39. B
Q40. D
Q41. A

Q42. B
Q43. B
Q44. A
Q45. B
Q46. (C) Assertion is true, reason is false

Q47. (B) Assertion and reason both are true but reason is not the
correct explanation of assertion
Q48. (A) Both Assertion and reason are true and reason is correct
explanation of assertion.
Q49. (A) Both Assertion and reason are true and reason is correct
explanation of assertion.
Q50. (D) Assertion is false, reason is true.

Q51 D
Q52 C
Q53 B
Q54 D
Q55 D
Q56 A

Q57 D

Q58 C

Q59 A

Q60 D

Q61 B

Q62 A
Q63 A
Q64 C
Q65 A
Q66.. a) Both Assertion and reason are true and reason is the correct
explanation of assertion.
Q67. c) Assertion is true, reason is false.
Q68. d) Assertion is false, reason is true.
Q69. a) Both Assertion and reason are true and reason is the correct
explanation of assertion.
Q70. c) Assertion is true, reason is false.

Name of the vetter- Kamal Kant Gupta

Name of the KV- No 2 Kanchrapara

Region- Kolkata

Mobile No-9493887480

E-mail ID - kamalkant.kv@gmail.com
Name of the Chapter- DATA FILE HANDLING

CBQ NO Question Content Learning Objective(if


Provided)
Q1. Ramesh is learning Python in preparation for an Application
internship exam. He is having a problem with one
question in which she has been assigned an incomplete
Python code (given below) to create a CSV file called
‘Employee.csv.’ Assist her in completing the code that
generates the CSV file with the given content.

Incomplete Code:
______ #Statement 1
Csvfile = open(______, _______, newline=’’)
#Statement 2
CsvObj = csv. ________( ________) #Statement 3
Rows = []
Fields = [‘Empnumber’, ‘EmpName’, ‘EmpDesig’,
‘EmpSalary’]
Rows.append(Fields)
for i in range(5):
Empno = input(“Enter Employee No:”)
Name = input(“Enter Employee Name:”)
Desig = input(“Enter Designation:”)
Salary = int(input(“Enter Salary:”))
records= [________________] #Statement 4
Rows.________(______) #Statement 5
_______._______(Rows) #Statement 6
Csvfile.close()

a. Identify the relevant module to import in the blank


space in line marked as Statement 1.
(A) import pickle (B) import txt
(C) import csv file (D) import csv
b. Identify the missing code for the blank space in line
marked as Statement 2.
(A) “Employee.txt”, ‘rb’ (B)
“Employee.csv”, ’wb’
(C) “Employee.csv”, ’w’ (D)
“Employee.dat”, ’w’
c. Choose the function name (with argument) that should
be used in the blank space of line marked as
Statement 3.
(A) writer(“Employee.csv”) (B) read(“Csvfile”)
(C) writer(CsvObj) (C) writer(Csvfile)
d. Identify the suitable code for blank space in line
marked as Statement 4.
(A) Empno, Name, Desig, Salary (B)
“Empno, Name, Desig, Salary”
(C) “Empno”, “Name”, “Desig”,”Salary” (D)
“Empno – Name- Desig – Salary”
e. Identify the suitable code for blank space in the line
marked as Statement 5.
(A) insert(data) (A)
delete(data)
(C) append(records) (D)
addrows(records
f. Identify the suitable code for blank space in the line
marked as Statement 6.
(A) Csvfile.load() (B)
CsvObj.dumprow()
(C) Records.reader() (D)
CsvObj.writerows()
Q2. Application
The owners of the ‘Foodmill’ store wish to generate a
bill for each transaction using a binary file. In order to do
this, they have recruited a friend who is learning Python.
The friend has made a file called ‘foodmill.dat’ that
contains information like Itemno, Item Name, Qty and
Price in order to compute Total Amount, but is having
problems finishing it. Assist the friend in finishing the
code.
Incomplete Code:
import ________ #Statement 1
File = _____('foodmill.dat','_____') #Statement 2
ch='y'
while True:
Itemno = input("Enter Item No:")
Product = input("Enter Product Name:")
Qty= int(input("Enter Quantity:"))
Price = int(input("Enter Price:"))
Amount=Qty *Price
records= [Itemno,Product,Qty,Price,Amount]
pickle.______________ #Statement 3
ch=input("Do you want to buy more....")
if ch=='y' or ch=='Y':
continue
else:
break
File.close()
def Total_Amount():
f= open('foodmill.dat','rb+')
total_Amt=0
try:
while True:
R=_________ #Statement 4
___________________ #Statement
5
print("You have purchased",R[2],R[1],"of
price","Rs",R[3],"and amount is", R[4])
____________: #Statement 6
f.close()
print("Total Amount is Rs",total_Amt)
a. Identify the relevant module to import in the blank
space in line marked as Statement 1.
(A) pickle (B) bin
(C) tsv (D) csv
b. Identify the code to open the file along with the access
mode so that every time the program is run, new
customer records will be added in Statement 2.
(A) open ‘rb’ (B) open ‘wb’
(C) open ‘r’ (C) write ‘w’
c. Identify the suitable code for blank space in the line
marked as Statement 3.
(A) load(records,file) (B)
dumps(record,file)
(C) dump(records,file) (C)
load(file,records)
d. Identify the suitable code for blank space in line
marked as Statement 4.
(A) pickle.load(F) (B) pickle.dump(f)
(C) pickle.load(R) (D) pickle.load(f)
e. Identify the suitable code to calculate the total Amount
in the line marked as Statement 5.
(A) total_Amt=R[4] (B)
total_Amt=R[3]+R[4]
(C) total_Amt+=R[4] (D)
total_Amt=R[4]*2
f. Identify the suitable keyword to handle the exception
(if any) that occurs during execution of the try
clause.
(A) catch (B) except
(C) stop (D) exception
Q3. A programmer has confusion in understanding the
behavior of opening a file in "w" mode. Clear his/her
confusion, by suggesting the correct option among the
given below.
The behavior of "w" mode is
A. Opening fails if the file exists already.
B. Opening fails if the file does not exist already.
C. Opening will be succeeded if file exists with
data and keeps the data intact.
D. Opening will be succeeded, if the file exists
replaces the contents, if do not exist, creates a
new file.

Q4. Rehang is assigned the task to storing the information of


his class mates as student records in a text file
“Stu2021.txt”. He wants to create a file to write the
records.
Which of the following is not a valid mode to open a file
for writing the data?

A. w
B. r+
C. r
D. w+

1. Abhinav is a student of class XII, he wants to create a file


through python program which can open in excel also,
what type of file you will suggest to create.
A. Binary
B. CSV
C. Both
D. None

1. Mrs. Bhatia is running her own boutique business. She


wants to store data of all orders permanently and fast
processing of data through her boutique software. Suggest
her to choose the appropriate technique among the
following.
A. She can use Python Dictionaries with
Binary file concept.
B. She can use Python Dictionaries with Text
files.
C. She can use Python Lists without the
Binary files concept.
D. She can use Python Dictionaries without
the Binary file concept.

1. Rohit, a class 12th student, wants to write a program to


read a binary file, Which python module needs to be
imported by Rohit in his program.
A. binary
B. pickle
C. data
D. file

Q5 Ramesh wants to write into an existing file ‘story.txt’ APPLICATION,


which already had some important content in it. He has
written the code given below. Help him to complete this ANALYSIS,
code. EVALUATION AND
CREATION
fout = open('story.txt',_________) # STATEMENT 1
print("Name of the file:", fout.name)
n = int(input("No. of lines to be entered:"))
l = []
for i in range(n):
fil_str = input("Enter string:")
fil_str = _________________ # STATEMENT 2
l.append(fil_str)
fout._______________ # STATEMENT 3
__________________ # STATEMENT 4

i) Complete the code for statement 1 by writing access KNOWLEDGE AND


mode to open the file for writing. (Consider file already UNDERSTANDING
exists with some important data)
(A) a
(B) r
(C) w
(D) b
ii) Complete the code for statement 2 by adding a newline APPLICATION
character to the string entered by the user.
(A) ‘\n’
(B) fil_str+newline
(C) fil_str+’\n’
(D) fil_str+’\N’
iii) Complete the code for statement 3 by replacing the spaces APPLICATION
with the code for writing multiple strings/lines at once in
the file.
(A) writeline()
(B) writelines(l)
(C) writelines()
(D) writestrings()
iv) Replace the code for statement 4 by closing the file. KNOWLEDGE AND
(A) f.close() UNDERSTANDING
(B) close()
(C) close(f)
(D) fout.close()
Q6 Deepti wants to write into an existing file ‘story.txt’ APPLICATION,
which already has some important content in it. She has ANALYSIS,
written the code given below. Help her to complete this EVALUATION AND
code and analyze the output. CREATION

fout = ________________________ # STATEMENT 1


print("Name of the file:", fout.name)
n = int(input("No. of lines to be entered:"))
for i in range(n):
fil_str = input("Enter string:")
fil_str = fil_str+"\n"
fout.______________ # STATEMENT 2
________________ # STATEMENT 3

i) Complete the code for statement 1 by writing code to KNOWLEDGE AND


open the file for writing. (Consider file already exists UNDERSTANDING
with some important data)
(A) open()
(B) open(story.txt,’w’)
(C) open(‘story.txt’,’a’)
(D) open(‘story.txt’)
ii) Complete the code for statement 2 by replacing the spaces APPLICATION
with the code for writing single string/line at a time in the
file.
(A) writeline()
(B) writeline(fil_str)
(C) writes(fil_str)
(D) write(fil_str)
iii) Replace the code for statement 3 by closing the file. KNOWLEDGE AND
(A) f.close() UNDERSTANDING
(B) close()
(C) close(f)
(D) fout.close()
iv) If user provides two strings as input : ANALYSIS,
String 1 : “PYTHON IS AN EASY LANGUAGE” EVALUATION AND
String 2 : “PYTHON IS POPULAR LANGUAGE” CREATION
What will be the content of the file after execution of the
code?
(A) PYTHON IS AN EASY LANGUAGE PYTHON IS
POPULAR LANGUAGE
(B) PYTHON IS AN EASY LANGUAGE
PYTHON IS POPULAR LANGUAGE
(C) PYTHON IS AN EASY LANGUAGEPYTHON IS
POPULAR LANGUAGE
(D) PYTHON IS POPULAR LANGUAGEPYTHON IS
AN EASY LANGUAGE
Q7 Consider a statement Application
fileobj = open(“myblog.txt”, ‘r’)
Which of the following options can be used to print the
last line of a text file ‘myblog.txt’?
(A) print(fileobj.readlines() -1)
(B) disp = fileobj.readlines()
print(disp[-1])
(C ) print(fileobj.readlines(-1))
(D) print(fileobj.read(-1))
Q8 Suppose the content of ‘moral.txt’ is: Application

What will be the output of the following code?


file = open(“moral.txt”)
line = file.read()
word = line.split()
for w in word:
if len(w)>8:
print(w)
file.close()
(A) Sometimes
weaknesses
discover
strengths
(B) sometimes
tested
weaknesses
strengths
(C) sometimes
weaknesses
strengths
(D) tested
show
our
but
Q9 During the practical examination of Computer Science, UNDERSTANDING
Amit has been assigned an KNOWLEDGE
incomplete search() function to search in a text file ANALYSIS
“EMP.txt”. The file “EMP.txt” is EVALUATION
created by his Teacher and the following information is
known about the file:
• File contains details of employees in text format
• File contains details of employees like Worker,
Supervisor, Manager
Amit has been assigned the task to complete the code and
print the number of the word Manager.

def search():
f = open("EMP.txt",) #Statement-1
A=____________________ #Statement-2
ct=0
for x in A:
p=x.split()
if p==”Manager”:
ct+=1
print(ct)

close() #___________________ #Statement-3


i. Name the function that can be used by Amit to read the
content of the file in statement-2.
a) f.read( )
b) f.readline ()
c) f.readlines( )
d)f.readl()
ii.Name the mode that can be used by Amit to read the
content of the file in statement-1.
a) w
b) r

c) readlines
d)readl()

iii Complete the function that can be used by Amit to


close the the file in statement-3.
a) f.read( )
b) f.close ()
c) f.readlines( )
d) f.closed ()

Q10 Sunaina wants to write a method in python to read lines UNDERSTANDING


from a text file MYNOTES.TXT and display those lines KNOWLEDGE
which start with alphabets 'K'-- ANALYSIS
def display (): EVALUATION
file=open(MYNOTES.TXT’ , ____) #
statement-1
lines=file._________() # statement-2
while line:
if line[0]==’K’ :
print(line)
line=file.______() # statement-3
file.close()
i.Name the mode that can be used by Amit to read the
content of the file in statement-1.
a) w
b) r
c) readlines
d)readl()

ii Name the function that can be used by Sunaina to read


the content of the file in statement-2.
a) f.read( )
b) f.readline ()
c) f.readlines( )
d)f.readl()
iii Name the function that can be used by Sunaina to read
the content of the file in statement-3.
a) f.read( )
b) f.readline ()
c) f.readlines( )
d)f.readl()

Q11
(CASE STUDY: 1)

f=open("data.txt",'w')
f.write("Hello")
f.write("Welcome to my Blog")
f.close()
f=open("data.txt",'r')
d=f.read(5)
print(d) # First Print Statement
f.seek(10) Knowledge
d=f.read(3) Understanding
print(d) # Second Print Statement Analysis
f.seek(13) Application
d=f.read(5)
print(d) # Third Print Statement
d=f.tell()
print(d) # Fourth Print Statement
1 Refer to the above code (CASE STUDY:1) Write the
output of the First Print statements :
a. Hello
b. Hell
c. ello
d. None of the above
2 Refer to the above code (CASE STUDY:1) : Write the
output of Second Print Statement
a. om
b. me
c. co
d. None of the above
3 Refer to the above code (CASE STUDY:1) : Write the
output of Third Print Statement
a. e to m
b. e to my
c. to my
d. None of the above
4 Refer to the above code (CASE STUDY:1) : Write the
output of Fourth Print Statement

a. 17
b. 16
c. 19
d. 18

Q12 CASE STUDY : 2

Your teacher has given you a method/function


FilterWords() in python which reads data from a text file
NewsLetter.TXT. Your teachers intentionally kept few
blanks in between the code and asked you to fill the
blanks so that the code will run to find desired result. Do
the needful with the following python code. Knowledge
Understanding
def FilterWords(): Analysis
c=0 Application
file=open('NewsLetter.TXT', '_____') #Statement-1
data = file._____ #Statement-2
line = _____ #Statement-3

linecount= _____: #Statement-4


print(“No of lines”,linecount)
_________ #Statement-5
FilterWords()
1 Fill in the statement 1 with appropriate access mode
a) rb

b) r

c) w

d) a

2 Fill the statement 2 with appropriate function to read 5


characters
a) read()

b) read(5)

c) readline(5)

d) get(5)

3 Fill the statement 3 to read the remaining content of the


file in list form.
a) file.read()

b) file.readlines()

c) file.readline()

d) readlines()

4 Fill the statement 4 to count the no. of lines in the file.


a) len() b) len(line) c) Len(line) d) len.line

5 Fill in the blank in Statement-5 to close the file.


a) file.close() b) File.Close() c) Close() d) end()

Q13. Suppose the content of "Myfile.txt" is Knowledge ,


Humpty Dumpty sat on a wall Understanding &
Humpty Dumpty had a great fall Application
All the king's horses and all the king's men
Couldn't put Humpty together again
Rohit, a student of class 12, is learning Python. During the
examination he has been given a stub Python program
(shown below) to count no of independent words has started
from vowels. Help him in completing the code.

myfile = open("Myfile.txt", _____) # Statement 1


vlist = list("aeiouAEIOU")
vc=0
s = myfile.read()
w=_________________ # Statement 2
for y in _______: # Statement 3
if ____ in _____: #Statement 4
vc+=1
print(vc)
myfile._________ # statement 5

(i) Identify the suitable code for blank space in the line
marked as Statement-1.
A. ‘w’
B. ‘w+’
C. ‘rb’
D. ‘r+’
(ii) Identify the suitable code for blank space in the line
marked as Statement-2.
A. Vlist.split()
B. S.split(‘*’)
C. s.split()
D. S.split()
(iii) Identify the suitable code for blank space in the line
marked as Statement-3.
A. vlist
B. s
C. w
D. myfile
(iv) Identify the suitable code for blank space in the line
marked as Statement-4.
A. y & w
B. y[0] & s
C. y & s
D. y[0] & w
(v) Identify the suitable code for blank space in the line
marked as Statement-5.
A. Off()
B. Close()
C. close()
D. open()
Q14. Consider the content of ‘rhyme.txt’ file:
Amit, a student of class 12 Science, is learning Python. During
the examination he has been given a stub Python program
(shown below) to count no of lines in ‘rhyme.txt’ file starts
with H or T has started from vowels. Help him in completing
the code.

fileobj=_________(‘rhyme.txt', ____ ) #
Statement 1
count = 0
L=fileobj.______________ #
Statement 2
for i in L:
if ( ______=='H' or ______==’T’ ): #
Statement 3

count=________ #
Statement 4
print(count) #
Statement 5
fileobj.close()

(i) Identify the suitable code for blank space in the line
marked as Statement-1.
A. Open () & ‘w’
B. open() & ‘w+’
C. open() & ‘r’
D. Open() & ‘r+’
(ii) Identify the suitable code for blank space in the line
marked as Statement-2.
A. read()
B. readlines()
C. readline()
D. readlines(5)
(iii) Identify the suitable code for blank space in the line
marked as Statement-3.
A. L[0]
B. i[0]
C. i
D. L[i]
(iv) Identify the suitable code for blank space in the line
marked as Statement-4.
A. 1
B. count+2
C. count+count
D. count+1
(v) Identify the ouput that will be display by Statement-5.
A. 1
B. 2
C. 3
D. 4
Q15 A Text file ‘data.txt’ content following lines. A Python Learning Objective
code is given to read the content of the file. Read the code
given below carefully and answer the following
questions.
File Content
Hello
Welcome to my blog
One of the best blog for Python

Code:
f=open("data.txt",'r')
d=f.read(5)
print(d) # Statement 1
f.seek(10)
d=f.read(3)
print(d) # Statement 2
f.seek(13)
d=f.read(5)
print(d) # Statement 3
d=f.tell()
print(d) # Statement 4
f.close()
f.read() ## Statement 5
1 What is output of statement 1 Application
(A) Hello
(B) ello
(C) hello
(D) Hello W
2 What is output of statement 2 Application
(A) com
(B) lco
(C) eco
(D) None of the above
3 What is output of statement 3 Application
(A) e to
(B) to my
(C) o my b
(D) Error
4 What is output of statement 4 Creation
(A) 18
(B) 19
(C) 17
(D) 16
5 What is out of statement 5 Analysis
(A) my blog
One of the best blog for Python
(B) One of the best blog for Python
(C) Error
(D) None of the Above
Q16. A Text file ‘myfav.txt’ content following lines. Python
code is given to count the number of word ‘this’ present
in the file. Read the code given below and answer the
following questions.
File Content:
This is India, this is great country. this is the place where
great personalities were born. this is the nation harmony.

Code:
file=open('myfav.txt','r')
count = 0
l=file.________() #statement 1
word= l.______() #statement 2
for i in word:
if(i=='______'): #statement 3
count=count+_______ #statement 4
print(count) # statement 5
file.close()
1 Write the correct function name that reads entire content Creation
as string (statement 1).
(A) Read
(B) read
(C) readline
(D) Readlines
2 Write the correct function name that breaks the string into Creation
list of words (statement 1).
(A) split()
(B) break()
(C) split(‘space’)
(D) break(‘space’)
3 File the blank that correct count the desired word in the Application
file (statement 3).
(A) This
(B) ‘This’
(C) ‘this’
(D) this
4 What is the literal value to increase the value of count by Analysis
1 statement 4
(A) 1
(B) 2
(C) 3
(D) 4
5 What is the output of statement 5 Analysis
(A) 5
(B) 2
(C) 3
(D) 4
Q17. Amit has written the following code in Python. Application
f=open("empfile.dat","ab") # Statement 1
print(f.closed) # Statement 2
f.close() # Statement 3
print(f.closed) # Statement 4
Answer the following questions based on the above
program
i.)In which mode the file will be opened.
(A) read binary
(B) write binary
(C) append binary
(D) None of the above
ii.)What will be the output of statement 2?
(A) False
(B) True
(C) 0
(D) 1
iii.)What will be the output of statement 4?
(A) False
(B) True
(C) 0
(D) 1
iv.)What is f in statement 1?
(A) List
(B) Dictionary
(C) File object
(D) Tuple
v.)Can we perform any task on the file ‘empfile.dat’
through the file object ‘f’ after statement 3?
(A) YES
(B) NO
(C) Can't say
(D) None of the above
Q18. Ravi has written the following code in Python. Application
fb=open("stu.dat","wb+") # Statement 1
print(fb.closed) # Statement 2
fb.close() # Statement 3
print(fb.closed) # Statement 4
Answer the following questions based on the above
program
i.)In which mode the file will be opened.
(A) read binary
(B) write and read binary
(C) append binary
(D) None of the above
ii.)Which operation is possible after statement 1?
(A) write
(B) read
(C) append
(D) write and read
iii.)What will happen if the file “stu.dat” is unavailable?
(A) File is created with ‘wb+’ mode
(B) File will be created in append mode
(C) File will be created in write only mode
(D) Error
iv.)What is fb in statement 1?
(A) Variable
(B) String
(C) List
(D) File object
Q19. Given a binary file “emp.dat” has structure (Emp_id, Application
Emp_name, Emp_Salary). Write a function in Python
countsal() in Python that would read contents of the file
“emp.dat” and display the details of those employee
whose salary is greater than 20000.
import pickle
def ____________: Line1
f = open (“emp.dat”, “________”) Line 2
n=0
try:
while True:
rec = ____________ Line 3
if rec[2] > 20000:
print(rec[0], rec[1], rec[2], sep=”\t”)
num = num + _______ Line 4
except:
f.close() Line 5

Q1. In the above program, choose correct option for Line


1.
(A) countsal() (B) CountSal() (C) Sal()
(D) Count()

Q2. In the above program, choose correct option for Line


2.
(A) ab (B) rb (C) wb
(D) None

Q3. In the above program, choose correct option for Line


3.
(A) Pickle.dump() (B) pickle.read()

(C) pikle.load() (D) None of these


Q4. In the above program, choose correct option for Line
4.
(A) -1 (B) 1 (C) 2
(D) 0

Q5. In the above program, choose correct option for Line


5.
(A) f.close() (B) f.exit() (C) f.stop()
(D) None
Q20. Mr. Zack has given the following code to modify the Application
records of employees from employee.dat used in above Knowledge
code. He has to increase Rs. 2000 in the salary of those
who are getting less than 15000. Mr. Zack has to find the
records and change the salary in place. His teacher gave
him partial code. Help him to complete the code.

import pickle as pk
found=False
emp={}
fin = ___________ #1 statement : open file both in read
write mode
# read from file
try:
while true:
pos= _______ #2 store file pointer position before
reading record
emp=_______ #3 to read the record in emp
dictionary
if emp[‘salary’]<15000:
emp[‘salary’]+=10000
_________ #4 place file pointer at exact
location of record
pickle.dump(emp,fin)
found=True
except EOFError:
if found==False:
print(“record not found”)
else:
print(“successfully updated”)
fin.close()
Q1. In #1 statement open the file in read and write mode.
Which statement is used out of the followings?
a) open(“employee.dat”,’rb+’)
b) open(“employee.dat”,’r+’)
c) open(“employee.dat”,’a’)
d) open(“employee.dat”,’rb’)
Q2. Choose the appropriate statement to complete #2
statement to store file pointer position before reading
record.
a) pk.seek(pos)
b) fin.tell()
c) pk.position()
d) pk.tell()
Q3. Choose the appropriate statement to complete #3
statement to read record in emp dictionary.
a) pk.read(fin)
b) pickle.load(fin,emp)
c) pk.dump(emp)
d) pk.load(fin)
Q4. Choose the appropriate statement to complete #4
statement to place file pointer at exact location of record.
a) fin.seek(pos)
b) pos=fin.seek()
c) fin.position()
d) none of the above
Q21 Given a binary file “emp.dat” has structure (Emp_id, Application
Emp_name, Emp_Salary). Write a function in Python
countsal() in Python that would read contents of the file
“emp.dat” and display the details of those employee
whose salary is greater than 20000.
import pickle
def_____: Line1
f = open (“emp.dat”, “_ ”) Line 2
n=0
try:
while True:
rec = ___________ Line 3
if rec[2] > 20000:
print(rec[0], rec[1], rec[2], sep=”\t”)
num = num +__________ Line 4
except:
f.______ Line 5

1. In above program , choose correct option for Line 1


A) countsal()
B) Countsal()
C) Sal()
D) Count()
2. In above program , choose correct option for Line 2
A) ab
B) rb
C) wb
D) None of the above

3. In above program , choose correct option for Line 3


A) pickle.dump()
B) pickle.read()
C) pickle.load()
D) None of the above

4. In above program , choose correct option for Line 4


A) -1
B) 2
C) 0
D) 1
Q22 A binary file “emp.dat” has structure [empid, empname, Application
empsalary]. Complete the code in the blanks so that it
would read contents of the file “salary.DAT” and display
the details of those teachers whose salary is above 20000.
import pickle
____________________________ # line1
try:
print("tr id\t tr Name\t tr Sal")
while True:
rec=___________.load(fobj) #line2
if rec[2]>_______: #line3
print(rec[0],"\t\t",rec[1],"\t\t",rec[2])
except:
____.close() #line4

1. To open the file for reading the data in line marked as


line-1.
A) fobj=open("emp.dat","rb")
B) fobj=open("emp.dat","r")
C) obj=open("emp.dat","r+")
D) fobj=open("data.dat","rb")

2. The module used in line2


A) PICKLE
B) pickling
C) pickle
D) None of these

3. Identify the salary to be checked in the code marked as


line-3.
A) 50000
B) 20000
C) 24000
D) 10000

4. Which of the following File Modes creates a new


binary file, if the file does not exist? (choose one/more)
A) ‘r’
B) ‘wb’
C) ‘w’
D) ‘a’

Q23. Read the program code given below and answer the Learning Objective:
following questions……..
((
Examine the code
Consider the following program to enter the following example to solve an
records as per below format in a binary file: application oriented
Item No integer problem and propose the
solution
Item_Name string
Qty integer
Price float
Number of records to be entered should be accepted from
the user. Read the file to display the records in the
following format:
Item No:
Item Name:
Quantity:
Price per item:
Amount: (to be calculated as Price * Qty)
))

import pickle
def input_record():
rec={}
rec['Item No']=int(input('Enter Item No'))
rec['Item_Name']=input('Enter Item Name')
rec['Qty']=int(input('Enter Quantity'))
rec['Price']=float(input('Enter Price'))
return rec

def create_file():
fileobject=open('data.dat','wb')
n=int(input('Enter Number of records to be entered'))
for i in range(n):
record=input_record()
pickle.dump(record,fileobject)
if i+1 < n:
print('Next Record')
print(n,'Records entered')

def show_records():
fileobject=open('data.dat','____') #statement1
i=1
while True: #statement2
try:
record=pickle.__________ #statement2
print('Record:',i)
print('Item No:',record['Item No'])
print('Item Name:',record['Item_Name'])
print('Quantity:',record['Qty'])
print('Price per item:',record['Price'])
print('Amount:', record['Qty'] * record['Price'])

i += 1
except:
pass

1 Fill in the blanks for statement1 , so that records can be


retrieved in memory.
(A) ab
(B). wb
(C). rb
(D) wb+
2 Fill in the blanks for statement2 , so that record can be
fetched from file.
(A) dump(record, fileobject)
(B) load( fileobject)
(C) dump( fileobject)
(D) load( record, fileobject)
Q24. Ajay want to read data from binary file “file.dat” help Understanding,
him to complete program. Knowledge,
import pickle Application, Evaluation
std = { }
fin = open(“file.dat”, ‘_____ ’) # (Statement1)
try:
while ____: # (Statement 2)
std = _______(fin) # (Statement3)
print(std)
____ : # (Statement 4)
fin.____() # ( Statement 5)

Help Ajay to complete the code as per the following


instructions.

a) Complete Statement1 to open binary file in read


mode.
b) Complete Statement 2 to place a condition till file
not reach at the end of file
c) Complete Statement 3 to read a record std
dictionary from fin
d) Complete Statement 4 it execute if error occurred
in try statement
e) Complete Statement 5 to Close file

Q25. Raj has been given following incomplete code, which Understanding,
takes a Employee’s details (Ecode, Ename, and Salary) Knowledge,
and writes into a binary file emp.dat using pickling. Application, Evaluation
import pickle
eno = int((input(“enter emp. Code”))
ename = input(“Enter emp. Name”)
sal = int(input(“Enter Emp. Salary”))
emp1 = {“Ecode”:eno, “Ename”:ename, “Salary”:sal}
with ___________________ as fh: # Statement 1
__________________ # Statement 2
_______________________ as fin # Statement 3
__________________ # Statement 4
print(Remp)
if Remp[“Salary”] > = 85000:
print(“Eligible for increment”)
____ : # Statement 5
print(“Not eligible for increment”)

Help Raj to complete the code as per the following


instructions.
a) Complete Statement1 so that the mentioned binary
file is opened for writing in fh object using a with
statement.
b) Complete Statement2 so that the dictionary
emp1’s contents are written on the file opened in
step (a)
c) Complete Statement3 so that the earlier created
binary file is opened for reading in a file object
namely fin, using a with statement.
d) Complete Statement4 so that the contents of open
file in fin are read into a dictionary namely Remp.
e) Complete Statement5 so that if condition false
“Not eligible for increment” message display.
Q26. Seema want to read data from a text file. She faced some Understanding
problems while executing the given code. Based on this
code find out the answers of the following questions.
def b_read( ):
import ___________ # Line1
f = open("data.dat" , ________ ) # Line 2
d = _____________ # Line 3
print(d)
___________ # Line
4
i) Which module Seema will use for binary file handling. Analysis
a) math
b) pickle
c) random
d) No need to import any module
ii) Write the correct code for line 2. Analysis
a) “r”
b) “rb”
c) “r+”
d) “wb”
iii) What code Seema should write to read data from file in Evaluation
line 3.
a) f.read()
b) f.readlines()
c) f.load(f)
d) None of the above
iv) Write to code in line 4 to access the function. Creation
a) b_read()
b) print(b_read())
c) call b_read()
d) No need to call any function
Q27. Amit has been assigned an incomplete search() function Understanding
to search in a pickled file student.dat. The File student.dat
is created by his Teacher and the following information is
known about the file.
• File contains details of students in [roll_no, name
,marks] format.
• File contains details of 10 students (i.e. from roll_no 1
to 10) and separate list of each student is written in the
binary file using dump().
Amit has been assigned the task to complete the code and
print details of roll number 5.
def search():
f = open("student.dat",____)
#Statement-1
__________:
#Statement-2
while True:
rec = pickle.____
#Statement-3
if(____):
#Statement-4
print(rec)
except:
pass
____________
#Statement-5
i) In which mode Amit should open the file in Statement-1? Analysis
a) r
b) r+
c) rb
d) wb
ii) Identify the suitable code to be used at blank space in line Creation
marked as Statement 2
a) if(rec[0]==1)
b) for i in range(10)
c) try
d) d) pass
iii) Identify the function (with argument), to be used at blank Evaluation
space in line marked as Statement-3.
a) load()
b) load(student.dat)
c) load(f)
a) d) load(fin)
iv) What will be the suitable code for blank space in line Creation
marked as Statement-4.
a) rec[0]==2
b) rec[1]==2
c) rec[2]==2
a) d) rec[0]==5
v) Which statement Amit should use at blank space in line Evaluation
marked as Statement-5 to close the file.
a) file.close()
b) close(file)
c) f.close()
a) d) close()
Q28. Mohak is collecting data of persons of a locality.He is
storing/retrieving data from a file LOCALITY.CSV. It
consists some records (sno, name, location). He has
written the following code in python. As a programmer,
you have to help him to successfully execute the program.

import ___________ # Line 1


def addRecord(Lst) # Line 2
f=open(“LOCALITY.CSV”, ___ ) # Line 3
obj=csv.writer(f)
obj.writerow(Lst)
_______ # Line 4

def ShowRecord():
with open(“LOCALITY.CSV”, ”r”) as file:
obj=csv.___________(file) # Line 5
for rec in obj:
print(rec[0], “#”, rec[2])

C_1=[1,’XYZ’, ‘Guwahati’]
C_2=[2,’PQRYZ’, ‘Dibrugarh’]
addRecord(C_1)
addRecord(C_2)
ShowRecord()
Understanding
1. Which module should be imported in Line 1?
(A) pickle
(B) csv
(C)file
(D) text
Creation
2. Which symbol is missing in Line 2?
(A) ::
(B) ,
(C) @
(D) :
Understanding
3. Which statement will be written at Line 4?
(A) f.close
(B) obj.close()
(C) f.close()
(D) obj.close
Application
4. Which function to be used in Line 5 to read the data
from a csv file.
(A) read()
(B) readline()
(C) readlines()
(D) reader()
Q29. Amayra has a branch1.csv file which has the name, class
and section of students. She receives a branch2.csv which
has similar details of students in second branch. She is
asked to add the details of branch2,csv into branch1.csv.
As a programmer, help her to successfully execute the
given task.
_____ csv #Statement1
file = open('branch1.csv', __b__ , newline="");
writer = csv. _____ (file) #Statement2
with open('branch2.csv','r') as csvfile ___#Statement3
data = csv.reader(csvfile)
for row in data:
writer.writerow(__)#Statement4
file. _____ ()#Statement5
Understanding
1. Which statement is to be used in place of blank space
of Statement 1?
(A) include
(B) import
(C) create space Creation
(D) includes

2. Which symbol is missing in Statement 3?


(A) ::
(B) ,
(C) @ Understanding
(D) :

3. Which statement will be written at Statement 5?


(A) f.close
(B) obj.close()
(C) f.close() Application
(D) obj.close

4. Fill in blank space in Statement 5 to write the data to a


csv file.
(A) write
(B) data
(C) row
(D) writeline
Q30. Rajeev sir, class teacher of class XI is writing a program APPLICATION
to create a Comma Separated file “Studrecord.dat” which
will contain roll no., name of student and total marks
obtained by the students of his class. He has written the
following code. As a programmer, help him to
successfully execute the given task.

import ________
#Line 1
f=open("student.csv","w",newline=
'')
s=csv.______ (f)
#Line 2
s.writerow(['RollNo','Name','Mark
s'])
rec=[]
while True:

print("ENTER STUDENT DETAILS:


")
r=int(input("ENTER ROLL NO.:
"))
n=input("ENTER NAME: ")
m=int(input("ENTER MARKS: "))
stu=[r,n,m]
rec._____(stu)
#Line 3
ch=input("DO YOU WANT TO
CONTINUE (Y/N): ")
if ch=='n' or ch=='N':
break

for i in rec:
s.______(i)
#Line 4
f.close()

i) Identify the suitable code for blank space in the line


marked as Line 1.
a) csv file
b) CSV
c) csv
d) cvs

ii) Choose the function name that should be used in the


blank space of the line marked as Line 2.
a) writer
b) write
c) writeline
d) writelines

iii) Write the method through which data can be added in


the list rec in line 3.
a) insert
b) add
c) append
d) into

iv) Write the function in line 4 by using which we will be


able to store records present in the list rec into the file
student.csv, one record at a time.
a) writerows
b) writelist
c) write
d) writerow

Q31 Prakash is making a software on “Countries and their APPLICATION


Currencies” in which various records are to be
stored/retrieved in “CURRENCY.CSV” data file. It
consists of a few records of Countries and their
Currencies. He has written the following code in python.
As a programmer, you have to help him to successfully
execute the program.

import csv
# Function to add a new record in CSV
file
def _________(Country,Currency):
# Statement-1
f=open("CURRENCY.CSV","__")
# Statement-2
fwriter=csv.writer(f)
fwriter.writerow([_____])
# Statement-3
f.close()
# Function to display all records from
CSV file
def ShowRec():
with open("CURRENCY.CSV","r") as
NF:
NewReader=csv._____ (NF)
# Statement-4
for rec in NewReader:
if len(rec)!=0:
print(rec[0],rec[1])
AddNewRec("INDIA","RUPEE")
AddNewRec("JAPAN","YEN")

i) Choose the Name of the function in Statement-1.


(A) AddNewRec
(B) Addnew
(C) Addrec
(D) AddNewRec()

ii) Choose the file mode to be passed to add new records


in Statement-2.
(A) w
(B) r
(C) w+
(D) a

iii) Identify the correct variables in Statement-3 to store


data to the file.
(A) country,currency
(B) Country,Currency
(C) Coun,Cur
(D) [Country,Currency]

iv) Choose the correct option for Statement-4 to read the


data from a csv file.
(A) Reader()
(B) reader()
(C) read
(D) reader

ANSWER

CBQ NO Answer
1.a. (D) import csv
1.b (C) “Employee.csv”, ’w’
1.c (D) writer(Csvfile)
1.d (A) Empno, Name, Desig, Salary
1.e (C) append(records)
1.f (D) CsvObj.writerows()
2.a (A) pickle 51
2.b (B) open ‘wb’
2.c (C) dump(records,file)
2.d (D) pickle.load(f)
2.e (C) total_Amt+=R[4]
2.f (B) except
3 1. D
3 2. C
3 3. B
3 4. A
3 5. B
4 i) (A) a
ii) (C) fil_str+’\n’
iii) (B) writelines(l)
iv) (D) fout.close()
5 i) (C) open(‘story.txt’,’a’)
ii) (D) write(fil_str)
iii) (D) fout.close()
iv) (B) PYTHON IS AN EASY LANGUAGE
PYTHON IS POPULAR LANGUAGE
6. B

7. A
8. i C ii B iii B
9. i B ii C iii B

10 1. b) r

10 2. b) read(5)

10 3. b) file.readlines()

10 4. b) len(line)
10 5. a) file.close()

11. Answer
(i) D
(ii) C
(iii) C
(iv) D
(v) C
12. Answer
(i) C
(ii) B
(iii) B
(iv) D
(v) D
13. 1 A
13. 2 A
13. 3 A
13. 4 A
13. 5 C
14. 1 B
14. 2 A
14. 3 D
14. 4 A
14. 5 C
15

(i.) A

(ii.) A

(iii.) B

(iv.) C

(v.) B

16.
(i.) B

(ii.) D
(iii.) A

(iv.) D

17. Q1. (A) countsal()


Q2. (B) rb
Q3. (C) pikle.load()
Q4. (B) 1
Q5. (A) f.close()
18. Q1. a) open(“employee.dat”,’rb+’)
Q2. b) fin.tell()
Q3. d) pk.load(fin)
Q4. b) pos=fin.seek()
19.
1 A
2 B
3 C
4 D
20.
1 A
2 C
3 B
4 B
21. C

22. B

23. a) fin = open(“file.dat”, ‘rb ’)


a) while True:
a) std = pickle.load(fin)
a) except :
a) fin.close()
24. a) with open(“emp.dat”, “wb”) as fh:
a) pickle.dump(emp1, fh)
a) with open(“emp.dat”, “rb”) as fin:
a) Remp = pickle.load(fin)
a) else:
25.
i B
ii B
iii C
iv A
26.
i C
ii C
iii C
iv A
v C
27. 1.(B)
2.(D)
3.(C)
4.(D)
28. 1.(B)
2.(D)
3.(C)
4.(C)
29. i)
ii)
iii)
iv)
30. i)
ii)
iii)
iv)

Name of the vetter- Kamal Kant Gupta

Name of the KV- No 2 Kanchrapara

Region- Kolkata

Mobile No- 9493887480

E-mail ID - kamalkant.kv@gmail.com
Name of the Chapter-

Question Question Content Learning Objective(if


No Provided)
Q1 A relative path always begins with root folder Knowledge
(A) True
(B) False
Q2 readlines() reads the entire file at a time Understanding
(A) True
(B) False
Q3. ‘with’ statement ensures that all the resources allocated to Understanding
the file objects get deallocated automatically
(A) True
(B) False

Q4. A binary file stores information in ASCII or Unicode Knowledge


character
(A) True
(B) False
Q5. Opening a file in write mode erases the previous data. Knowledge
(A)True
(B)False
Q6. The absolute paths are from the topmost label of the
directory structure
Q7. The relative path are relative to the current working
directory.
Q8. The relative path for a file always remain the same even
after changing the directory.
Q9. If a no path is given with the file name in the file open()
,then the file must exist in the current directory.
Q10. In Microsoft windows two files can have same pathname.

Q11. When an existing file is opened in appending mode than KNOWLEDGE AND
file pointer is present at the end of the file. UNDERSTANDING
Q12. If a file is opened in r+, w+ or a+ mode, it can be used for KNOWLEDGE AND
both reading and writing. UNDERSTANDING
Q13. When we are writing strings using the write() method into KNOWLEDGE AND
a file one by one using iteration then a newline character UNDERSTANDING
is appended to each string by default so that all strings are
written in different lines in the file.
Q14 If a file is opened with “with open() as f” syntax then APPLICATION
after the control exiting the “with open()” block the file
get closed itself. (where f is file stream object)
Q15 A user wants to open a file ‘story.txt’ without losing the ANALYSIS,
content of the file and wants to continue writing after the EVALUATION AND
existing content. Also, if a file does not exist the file CREATION
should be created itself. He/she opened the file with
syntax :
f = open(“story.txt”, ‘r+”)
Is this statement true or false?
Q16. The file open using the with statement will close Understanding
automatically after with block is over.
Q17. The file mode “w” & “w+” are the same. Knowledge
Q18. When open a file into append mode , if the file does not Knowledge
exist , an error has been occurred.
Q19. The read( ) function reads the entire file at a time. Understanding
Q20 The readlines( ) function read the entire file in a list of Analysis
strings where each line is stored as one string.
Q21 Text file mode ‘a’ is in write only mode? KNOWLEDGE
(A)True (B) False
Q22. Text file mode ‘w+’ refer to write and read mode file? KNOWLEDGE
(A)True (B) False
Q23. A close() function breaks the link of file –object? KNOWLEDGE
(A)True (B) False
Q24. The following syntax is not correct- KNOWLEDGE
Myfile=open(r’E:\poem.txt’,”r”)

(A)True (B) False


Q25. Readline() , reads all lines and returns them in a list. KNOWLEDGE
(A)True (B) False
Q26. The read() operation reads the entire file at once. Knowledge
a) True b) False
Q27. tell() will return the current position of file pointer in the Knowledge
file

a) True b) False

Q28. f.seek(10,0) will move 10 bytes forward from beginning Understanding


of file.

a) True b) False

Q29. Writer() method is used to write the objects in a binary Knowledge


file.

a) True b) False

Q30. dump( ) method is used to read data from a binary file Understanding

a) True b) False
Q31 read() method will read all the line of text file and return understanding
them in the form of list
(True/False)
Q32 Tell() method will identify the current location of file understanding
pointer in the file (True/False)
Q33 Open() method in read mode will create the file understanding
(True/False)
Q34 Readlines() method will returns the text file contents in understanding
the from of list of lines
(True/False)
Q35 Readline() method will returns the text file contents in the understanding
from of list of lines
(True/False)
Q36 f.seek (10,0) will move 10 bytes forward from beginning of file. Application
(A) True
(B) False

Q37 readlines( ) function returns all the words of the file in the Understanding
form of List. (T/F)
(A) True
(B) False

Q38 seek() function returns the current position of the file pointer Knowledge
(A) True
(B) False

Q39 readchar() function reads the all characters from the file Knowedge
(A) True
(B) False

Q40 readlines(5) read 5 lines from the file Application


(A) True
(B) False

Q41 The delimiter is required to end a binary file in Python. Understanding


Q42 The file mode “rb” & “rb+” are the same. Analysis
Q43 If the file does not exist and we open a file into append Knowledge
mode then an error occurs.
Q44. In ‘rb’ mode of Python a file must exist otherwise an Understanding
error occurs.
Q45. Binary files are not in human readable format. Understanding
Q46 In binary file data is stored in the same format that is Application
understand by the computer.
Q47 In append mode of binary file, the file pointer will remain Evaluation
at the end of the file.
Q48 The ‘r+b’ mode is used to read a binary file. Knowledge

Q49 There will be a line delimeter in a binary file. Understanding

Q50 The Binary files are used to store large data such as Analysis
images, video files, audio files etc.
Q51 Binary file stores information in ASCII or UNICODE Understanding
characters
A) TRUE
B) FALSE
Q52 The flush function forces the writing of data on the disk Understanding
still pending in output buffer.
A) TRUE
B) FALSE
Q53 Every line is a binary file is terminated with a EOL Knowledge
character.
A) TRUE
B) FALSE
Q54 The tell method tells the current position of the file Knowledge
pointer within the file
A) TRUE
B) FALSE
Q55 The dump method is used to read data from the binary file Knowledge
A) TRUE
B) FALSE
Q56 The pickle module can be used to directly store the Awareness about pickle
python module
objects onto the disk file.
Q57 pickle.loads( ) read the next line and store into disk file. Knowledge of basic
working of load( )
Q58 Deserialisation of records from file through pickle Awareness about basic
module should be guarded through try.. catch .. block. coding steps of using
pickle
Q59 A binary file 'employee.dat' contains 100 records, to add a Know about opening
new record into file, the file should be opened in 'wb' modes in case of binary
mode. file
Q60 Pickling is the process by which a Python object is Knowledge about saving
converted to a byte stream. process through pickle
module
Q61 A binary file can store data in the form of 0 and 1 Understanding
a) True
b) False
Q62 File object and file handle is the same thing Knowledge
a) True
b) False
Q63. Pickle.dump() function is use for writing data in binary Application
file.
a) True
b) False
Q64. pickle module contains read() and write() function. Knowledge
a) True
b) False
Q65. wb+ and w+b are same in respect of binary file. Knowledge
a) True
b) False
Q66. The load() function of the pickle module perform Evaluation
pickling.
a) TRUE
b) FALSE
Q67 File.seek(5,0) will move 5 bytes forward from the Analysis
beginning of the file.
a) TRUE
b) FALSE
Q68 There is a delimiter to end a line in Binary File. Knowledge
a) TRUE
b) FALSE
Q69 tell() method of Python tells us the current position Analysis
within the file.
a) TRUE
b) FALSE
Q70 When you open a file for writing, if the file exists, the Analysis
existing file is overwritten with the new file.

a) TRUE
b) FALSE
Q71 We cannot insert multiple rows in csv file using python Application
csv module
Q72 The default line terminator is \n in csv file Understanding
Q73 We can import csv module functions in following Creation
manner:
from csv import writerow, reader
Q74 A CSV file is a plain text file that can be opened in all kid Understanding
of programs
Q75 We have to insert header row in csv file using write() function Evaluation
as it is not included by default
Q76 A csv file is a binary file. Knowledge
(A) True
(B) False
Q77. The separator character of csv files is called delimiter. Knowledge
(A) True
(B) False
Q78 The csv files only take a comma as delimiter. Knowledge
(A) True
(B) False
Q79 You cannot insert multiple rows in a csv file using the csv Application
module.
(A) True
(B) False
Q80 You can import csv module functions for reading from Application
csv file and writing into csv file in the following manner:
from csv import writer, reader
(A) True
(B) False

ANSWER

Question No Answer
Q1 (B) False
Q2 (A) True
Q3. (A) True
Q4. (A) True
Q5. (A) True
Q6. True

Q7. True

Q8. False

Q9. True

Q10. False

Q11. True
Q12. True
Q13. False
Q14 True
Q15 False
Q16. True

Q17. False
Q18. False
Q19. True
Q20 True
Q21 True
Q22. True

Q23. True

Q24. False

Q25. False

Q26. True
Q27. True
Q28. True
Q29. False
Q30. False
Q31 False
Q32 True
Q33 False
Q34 True
Q35 False
Q36 A
Q37 A
Q38 B
Q39 B
Q40 B
Q41 False
Q42 False
Q43 False
Q44. True
Q45. True
Q46 True

Q47 True

Q48 False

Q49 False

Q50 True

Q51 FALSE
Q52 TRUE
Q53 FALSE
Q54 TRUE
Q55 FALSE
Q56 True

Q57 False

Q58 True

Q59 False

Q60 True

Q61 False
Q62 True
Q63. True
Q64. False
Q65. True
Q66. FALSE
Q67 TRUE
Q68 FALSE
Q69 TRUE
Q70 TRUE
Q71 False
Q72 True
Q73 True
Q74 False
Q75 True
Q76 b) False

Q77. a) True

Q78 b) False

Q79 b) False

Q80 a) True

Name of the vetter- KAMAL KANT GUPTA

Name of the KV- NO 2 KANCHRAPARA

Region- KOLKATA

Mobile No- 9493887480

E-mail ID - kamalkant.kv@gmail.com

You might also like