Binary File MCQ Question Bank For Class 12 - CBSE Python
Binary File MCQ Question Bank For Class 12 - CBSE Python
cbsepython.in/binary-file-mcq-question-bank-for-class-12
1. Out of the followings which mode is used for both reading and writing in binary format in file?
a) wb
b) wb+
c) w
d) w+
b) wb+
b) When you open binary file in text editor will show garbage values
a) wb mode is used to open binary file in write mode and wb+ mode open binary file both for read and
write operation.
c) File pointer is at beginning of file in wb mode and in wb+ at the end of file
d) No difference
a) wb mode is used to open binary file in write mode and wb+ mode open binary file both for read and
write operation.
c) Both a and b
d) None of these
c) Both a and b
5. Which method is used to convert Python objects for writing data in binary file?
a) write()
b) load()
c) store()
d) dump()
d) dump()
d) None of these
a) r
b) rb
c) wb
d) wb+
a) r
8. Which of the following function is used to read the data in binary file?
a) read()
b) open()
c) dump()
d) load()
d) load()
9. Suresh wants to open the binary file student.dat in read 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) w
d) wb
b) rb
10. This method returns an integer that specifies the current position of the file object.
a) seek()
b) load()
c) position()
d) tell()
d) tell()
Mr. Zack Sullivan loves programming. He joined an institute for learning. He is learning python. He learned
all the python concepts like strings, lists, tuple , dictionaries etc. but he wants to learn file handling in
python. He is trying to learn binary file handling. His teacher gave him partial code to write and read data
from employee.dat having structure empno, name, salary. Help Zack to complete the code:
___________________ # statement 1
def addrecords():
dict={}
ch=’y’
while ch==’y’:
dict={‘empno’:eno,’name’:nm,’salary’:sal}
____________________ # statement 3
fw.close()
def display():
dict={}
dict=____________ # statement 5
fr.close()
print(“data :”,dict)
12. Help Zack to import the module to perform binary file operation in statement 1.
a) csv
b) random
c) pickle
d) file
c) pickle
13. Which statement is used from the following for statement 2 to open the binary file in write mode?
a) open(“employee.dat”,’w’)
b) open(“employee.dat”,’wb’)
c) open(“employee.dat”,’w+’)
d) open(“employee.dat”,’r’)
b) open(“employee.dat”,’wb’)
14. Which statement is used from the following for statement 3 to write dictionary data created in above
code, namely dict, is written in binary file employee.dat file?
a) pickle.dump(dict,fw)
b) pickle.write(dict,fw)
c) pickle.save(dict,fw)
d) pickle.store(dict)
a) pickle.dump(dict,fw)
15. Which statement is used from the following for statement 4 to open the binary file in read mode?
a) open(“employee.dat”,’r’)
b) open(“employee.dat”,’r+’)
c) open(“employee.dat”,’a’)
d) open(“employee.dat”,’rb’)
d) open(“employee.dat”,’rb’)
16. Compelete statement 5 to read data in dictionary namely dict from the opened binary file?
a) dict=pk.read(fr)
b) dict=pickle.load(fr)
c) pickle.load(dict,fr)
d) none of these
b) dict=pickle.load(fr)
Now Mr. Zack has given the following code to modify the records of employees from employee.dat used
in above 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={}
try:
while true:
if emp[‘salary’]<15000:
emp[‘salary’]+=10000
pickle.dump(emp,fin)
found=True
except EOFError:
if found==False:
else:
print(“successfully updated”)
fin.close()
17. 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’)
a) open(“employee.dat”,’rb+’)
18. 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()
b) fin.tell()
19. 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)
d) pk.load(fin)
20. 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()
b) pos=fin.seek()
Binary file: basic operations on a binary file: open using file open modes (rb, rb+, wb, wb+, ab, ab+), close a
binary file
21. If a file is opened for reading, which of the following statements is not true?
b) If the file exists at the specified path, the file is successfully opened.
c) The file even if at a different location on disk other than the specified path, will get opened
d) Python gives error if the file does not exist at the specified path
c) The file even if at a different location on disk other than the specified path, will get opened
a) Infi.read()
b) infi.read(24)
c) Infi.readline()
d) infi.readlines
b) infi.read(24)
a) a str
b) a list of integers
d) a list of lines
d) a list of lines
a) ab
b) rw
c) wb
d) w+
b) rw
25. Which of the following functions do you use to write data in the binary format?
a) Write()
b) output()
c) dump()
d) send()
c) dump()
26. Which of the following command is used to open a file “c:\path.txt” in read mode only?
a) Fin=open(“c\path.txt”,”r”)
b) fin=open(“c\\path.txt”,”r”)
c) Fin=open(file=”c:\path.txt”,”r+”)
d) fin=open(file=”c\\path.txt”,”r+”)
b) fin=open(“c\\path.txt”,”r”)
27. Which of the following is not a correct statement for binary files?
28. Which of the following commands can be used to read the entire contents of a file as a string using
the file object <tmpfile>?
a) tmpfile.read(n)
b) tmpfile.read()
c) tmpfile.readline()
d) tmpfile.readlines()
b) tmpfile.read()
29. Which of the following command is used to open a file “c:\temp.txt” for writing in binary format only?
a) Garbage values
b) ASCII values
c) Binary character
d) Unicodes
a) Garbage values
31. Ms. Suman is working on a binary file and wants to write data from a list to a binary file. Consider list
object as l1, binary file suman_list.dat, and file object as f.
(i) Which of the following can be the correct statement for her?
a) f = open(“suman_list”,”wb”); pickle.dump(l1,f)
b) f = open(“suman_list”,”rb”); l1=pickle.dump(f)
c) f = open(“suman_list”,”wb”); pickle.load(l1,f)
d) f = open(“suman_list”,”rb”); l1=pickle.load(f)
a) f = open(“suman_list”,”wb”); pickle.dump(l1,f)
(ii ) Which option will be correct for reading file for suman?
a) f = open(„suman_list‟,‟rb‟)
b) f = open(„suman_list‟,‟r‟)
c) f = open(„suman_list‟,‟r+‟)
d) f = open(„suman_list‟,‟ab‟)
a) f = open(„suman_list‟,‟rb‟)
(iii) In which of the file mode existing data will be intact in binary file?
a) a
b) ab
c) w
d) wb
b) ab
a) import – pickle
b) pickle import
c) import pickle
c) import pickle
b) To store data
d) None of these
32. Ms. Sejal is working on the sports.dat file but she is confused about how to complete the code to
read the data from the binary file. Suggest a suitable line for her to fulfil her.
____________ # Statement 1
f1 = _______________ # Statement 2
_________________ # Statement 3
print(data)
f1. close ()
sports.read()
(i) Identify the suitable code for blank space in line marked as Statement-1.
a) pickle import
b) import pickle
c) import.pickle
b) import pickle
(ii) Identify the suitable code for blank space in line marked as Statement-2.
a) f1 =open(“sports.dat”,”wb”)
b) f1 =open(“sports.dat”,”r”)
c) f1 =open(“sports.dat”,”rb”)
c) f1 =open(“sports.dat”,”rb”)
(iii) Identify the suitable code for blank space in line marked as Statement-3.
a) data = pickle.load(f1)
b) data = pickle.dump(f1)
c) data = pickle.load(f)
d) data = pickle.dump(f)
a) data = pickle.load(f1)
c) read only
d) none of these
(v) Which of the following file modes will not delete the existing data in binary file ?
a) wb
b) w
c) a
d) ab
d) ab
33. Sarita is trying to add data onto a existing binary file and is facing difficulty in completing the
code.Help her to fill the gaps in the code.
Incomplete Code:
import pickle
_____________________________ # Statement 1
recno=1
print()
#taking data from user and dumping in the file as list object
while True:
ename=input_____________________ # Statement 2
allow=int(input(“\tAllowances : “))
totsal=ebasic+allow
edata=[eno,ename,ebasic,allow,totsal]
pickle.dump(_____________) # Statement 3
recno=recno+1
if ans.lower()==’n’:
print()
bfile.tell())
______() # Statement 4
(i) To open the file for writing the data in line marked as Statement-1.
a) bfile=open(“empfile.dat”,”ab”)
b) bfile=open(“empfile.dat”,”a”)
c) bfile=open(“empfile.dat”,”wb”)
d) bfile=open(“empfile.dat”,”w”)
a) bfile=open(“empfile.dat”,”ab”)
(ii) To accept employee name from the user in line marked as Statement-2.
a) input(“\tEmployee Name : “)
b) input(Employee Name 🙂
c) input(“Employee Name )
d) None of these
a) input(“\tEmployee Name : “)
(iii) Identify the suitable code for blank space in line marked as Statement-3.
a) edata,bfile()
b) edata,bfile
c) data,bfile
d) edata,file
b) edata,bfile
(iv) Identify the suitable code for blank space in line marked as Statement-4.
a) bfile.close()
b) bfile.close
c) file.close()
d) none of these
a) bfile.close()
(v) Which of the following is the correct syntax to read from a file using load function ?
a) pickle.load(<filehandle>)
b) <object> – load.pickle(<filehandle>)
c) <object> – pickle.load(<filehandle>)
c) <object> – pickle.load(<filehandle>)
34. A Binary file Stock.dat has a structure [pno,pname,qty,price].A user defined function Createfile() to
input data for 3 records and add to stock.dat .There are some blanks help in filling the gaps in the code:
Incomplete Code :
def createfile():
File=open(“d:\\Stock.dat”,‟____‟) #Statement 2
record=[pno,pname,qty,price]
_______________ # Statement 3
Print(“Record inserted”)
File.close()
Createfile()
(i) Identify the suitable code for blank space in line marked as Statement-1.
a) csv
b) CSV
c) pickle
d) PICKLE
c) pickle
(ii) Identify the suitable code for blank space in line marked as Statement-2.
a) wb
b) ab
c) w
d) a
b) ab
(iii) select correct statement to write data into file for Statement-3.
a) pickle.dump(record,file)
b) pickle.dump(record)
c) pickle.dump(file,record)
d) pickle.load(record,file)
a) pickle.dump(record,file)
a) Pickling
b) Unpickling
b) Unpickling
a) save
b) close
c) end
d) write
b) close
35. A binary file “STUDENT.DAT” has structure [admission_number, Name, Percentage]. Write a function
countrec() in Python that would read contents of the file “STUDENT.DAT” and display the details of those
students whose percentage is above 75. Also display number of students scoring above 75%.
def countrec():
fobj=open(“_____________”,”rb”) # line2
num = 0
try:
while ______: # line3
rec=pickle.load(fobj)
if rec[2]>75:
num = num + 1
print(rec[0],rec[1],rec[2])
except:
fobj.close()
return num
a) import
b) IMPORT
c) Import
a) import
a) STUDENT.DAT
b) STUDENTS.DAT
c) SCHOOL.DAT
a) STUDENT.DAT
a) True
b) False
c) true
d) TRUE
a) True
36. Ms.Anita is unable understand what can be the output of the following code.Help her in getting the
output.
Import pickle
L=[20,40,50]
f=open(“list.dat”,‟wb‟)
Pickle.dump(l,f)
f.close()
f=open(“list.dat”,‟rb‟)
data=pickle.load(f)
f.close()
print(data)
[20,40,50]
b) [20,30,50]
c) [20,30,50]
d) No output
[20,40,50]
37. A binary file “salary.DAT” has structure [teacherid, teacher name, salary]. 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:
while True:
rec=___________.load(fobj) #line2
if rec[2]>_______: #line3
print(rec[0],”\t\t”,rec[1],”\t\t”,rec[2])
except:
____.close() #line 4
(i) To open the file for writing the data in line marked as line-1.
a) fobj=open(“salary.dat”,”rb”)
b) fobj=open(“salary.dat”,”r”)
c) fobj=open(“salary.dat”,”r+”)
d) fobj=open(“data.dat”,”rb”)
a) fobj=open(“salary.dat”,”rb”)
a) PICKLE
b) pickling
c) pickle
d) None of these
c) pickle
a) 50000
b) 20000
c) 24000
d) 10000
b) 20000
(iv) Which of the following File Modes creates a new file, if the file does not exist? (choose one/more)
a) “r”
b) “bw”
c) “w”
d) “a”
c) “w”
38. Mr. Rohan wants to modify salary of employee having a structure[eid,ename ,salary],but unable to fill
the gaps in the code. Help him to complete the code
Import pickle
f = open(‘d:/student.dat’,’rb’)
reclst = []
try:
rec = pickle.load(f)
reclst.append(rec) #line2 statement to add items in list at the end one by one
except EOFError:
break
f.close()
if reclst[i][‘eid’]==r:
reclst[i][‘salary’] = m
for x in reclst:
pickle.dump(x,f)
f.close()
a) PICKLE
b) pickling
c) pickle
d) None of these
c) pickle
a) w
b) wb
c) r
d) rb
b) wb
39. A binary file sports.dat contains information in the following structure:( Event, Participant )
A code is shown below which is incomplete that would read contents from the sports.dat and creates a
file named Athletic.dat copying only those records from sports.dat where the event name is “Athletics”.
import pickle
ath ( f1 , f2 ) :
l = pickle.load ( f1)
for t in l :
if ( t [ 0 ] == “________________” ) : #line 1
pickle.__________ ( t , f2 ) #line 2
f1 = open ( “ sports.dat “ , “ rb ” )
f2 = open ( “ athletics.dat “ , “ wb “ )
f.close()
f1.close()
a) Athletics
b) Sports
c) Games
d) None of the above
a) Athletics
(ii) The function to copy the data into other binary file2
a) DUMP
b) close
c) dump
d) None of these
c) dump
(iii) Information stored on a storage device with a specific name is called as __________.
a) array
b) dictionary
c) file
d) tuple
c) file
a) ab
b) rw
c) r+
d) w+
b) rw
40. A function searchprod( pc) in python is created to display the record of a particular product from a
file product.dat whose code is passed as an argument. Structure of product contains the following
elements [product code , product price].There is some problem in completing the code,help to finish the
code:
f = ________(‘d:/product.dat’,’rb’) #line1
flag = False
while True:
try:
rec = pickle.load(f)
print(‘Product code:’,rec[‘pcode’])
print(‘Price:’,rec[‘price’])
flag = True
except EOFError:
break
if flag == False:
f.close()
a) close
b) open
c) OPEN
b) open
(ii) The variable used to accept product code entered by the user for the line2
a) pcode
b) pc
c) code
d) None of these
b) pc
import pickle module, dump() and load() method, read, write/create, search, append and update
operations in a binary file
41. _____________ is the process of converting Python object hierarchy into a byte stream so that it can
be written into a file.
a) Pickling
b) Unpickling
c) Dumping
d) Loading
a) Pickling
a) Pickling
b) Unpickling
c) Dumping
d) Loading
b) Unpickling
43. ___________ of pickle module will unpickle the data coming from the binary file.
a) load()
b) dump()
c) writer()
d) insert()
a) load()
44. ___________ of pickle module will pickle the data in the binary file.
a) load()
b) dump()
c) writer()
d) insert()
b) dump()
45. _______________ will return the current position of file pointer in the file
a) seek()
b) search()
c) tell()
d) print()
c) tell()
46. ________ places the file pointer at the specified position in the open file.
a) seek()
b) search()
c) tell()
d) print()
a) seek()
47. F.seek(20,0) will move the file pointer 20 bytes in forward direction from beginning of file. State True
or False
a) True
b) False
a) True
48. F1.seek(-5,1) will move the file pointer 5 bytes backwards from end of file. State True or False
a) True
b) False
b) False
49. Syntax of seek function in Python is myfile.seek(offset, reference_point) where myfile is the file
object. What is the default value of reference_point?
a) 0
b) 1
c) 2
d) 3
a) 0
51. Archit wants to create and display a Binary file named “Myfile.DAT”. Complete the missing code to
open, create and display the file.
double=[]
for i in range(1,11):
double.append(2*i)
fo=__________________ #Line2
pickle.________________ #Line 3
fo.close()
fin=___________________ #Line4
result=________________ #Line 5
fin.close()
a) csv
b) pickle
c) binary
d) bin
b) pickle
(ii)Fill in the blank in Line 2 to open the file for writing the contents of the file.
a) open(“Myfile.dat”,”w”)
b) open(“Myfile.dat”,”r”)
c) open(“Myfile.dat”,”wb”)
d) open(“Myfile.dat”,”rb”)
c) open(“Myfile.dat”,”wb”)
(iii) Fill in the blank in Line 3 with the function to write entire contents to file.
a) load(double,fo)
b) dump(double,fo)
c) writer(double)
d) insert(double,fo)
b) dump(double,fo)
(iv) Fill in the blank in Line 4 to open the file for displaying contents of file.
a) open(“Myfile.dat”,”w”)
b) open(“Myfile.dat”,”r”)
c) open(“Myfile.dat”,”wb”)
d) open(“Myfile.dat”,”rb”)
d) open(“Myfile.dat”,”rb”)
(v) Fill in the blank in Line 5 read the contents of the file.
a) pickle.read(fin)
b) pickle.readline(fin)
c) pickle.readlines(fin)
d) pickle.load(fin)
d) pickle.load(fin)
52. Rohit has been given the following incomplete code for entering his details(Name,contact number
and address) to a file “Personal.DAT” and display the contents. Complete the missing code to open,
create and display the file.
mydata=[]
name=input(“Enter Name:”)
address=input(“Enter address:”)
mydata=[name,contactno,address]
f1=__________________ #Line2
pickle.________________ #Line 3
f1.close()
f2=___________________ #Line4
result=________________ #Line 5
f2.close()
a) csv
b) pickle
c) binary
d) bin
b) pickle
(ii) Fill in the blank in Line 2 to open the file for writing the contents of the file.
a) open(“Personal.dat”,”w”)
b) open(“Personal.dat”,”r”)
c) open(“Personal.dat”,”wb”)
d) open(“Personal.dat”,”rb”)
c) open(“Personal.dat”,”wb”)
(iii)Fill in the blank in Line 3 with the function to write entire contents to file.
a) load(mydata,f1)
b) dump(mydata,f1)
c) writer(mydata)
d) insert(mydata,f1)
b) dump(mydata,f1)
(iv) Fill in the blank in Line 4 to open the file for displaying contents of file.
a) open(“Personal.dat”,”w”)
b) open(“Personal.dat”,”r”)
c) open(“Personal.dat”,”wb”)
d) open(“Personal.dat”,”rb”)
d) open(“Personal.dat”,”rb”)
(v) Fill in the blank in Line 5 read the contents of the file.
a) pickle.read(f2)
b) pickle.readline(f2)
c) pickle.readlines(f2)
d) pickle.load(f2)
d) pickle.load(f2)
53. You are provided with some incomplete code for entering student‟s details (Rollno, Name and
marks) to a file “Student.DAT” and display the contents. Complete the missing code to open, create and
display the file.
data=[]
name=input(“Enter Name:”)
marks=int(input(“Enter mark:”))
data=[rollno,name,marks]
fout= open(“Student.dat”,”wb”)
pickle.________________ #Line 2
fout.close()
fin=___________________ #Line3
output=________________ #Line 4
fin.close()
if ____________>=33: #Line5
print(output[1],” passed”)
else:
print(output[1],” failed”)
a) csv
b) pickle
c) binary
d) bin
b) pickle
(ii) Fill in the blank in Line 2 with the function to write entire contents to file.
a) load(data,fout)
b) dump(data,fout)
c) writer(data)
d) insert(data,fout)
b) dump(data,fout)
(iii) Fill in the blank in Line 3 to open the file for displaying contents of file.
a) open(“Student.dat”,”w”)
b) open(“Student.dat”,”r”)
c) open(“Student.dat”,”wb”)
d) open(“Student.dat”,”rb”)
d) open(“Student.dat”,”rb”)
(iv) Fill in the blank in Line 4 read the contents of the file.
a) pickle.read(fin)
b) pickle.readline(fin)
c) pickle.readlines(fin)
d) pickle.load(fin)
d) pickle.load(fin)
(v) Fill in the blank in Line 5 to display he status of students(passed/failed) based on their mark.
a) Output[0]
b) Output[1]
c) Output[2]
d) output
c) Output[2]
54. Ritesh wants to perform the following binary file operations, as a part of his assignment, with the
help of two user defined functions/modules:
1. AddEmp() to create a binary file called Employee.DAT containing employee information – employee
number, name and salary.
2. ViewEmp() to display the name and salary of employees who are getting Rs.50000 above as salary.
The function should also display the average salary.
import pickle
def AddEmp():
while True:
if Choice in “nN”:
break
F.close()
def ViewEmp():
Total=0
Countrec=0
C50K=0
F=open(“Employee.DAT”,”rb”)
while True:
try:
Countrec+=1
Total+=R[2]
C50K+=1
except:
break
if C50K==0:
AddEmp()
ViewEmp()
(i) Write statement #Line1, to open the file “Employee.DAT” for writing only in binary format?
a) F= open(“Employee.DAT”,’wb’)
b) F= open(“Employee.DAT”,’w’)
c) F= open(“Employee.DAT”,’wb+’)
d) F= open(“Employee.DAT”,’w+’)
a) F= open(“Employee.DAT”,’wb’)
(ii) Write statement, #Line2, to write the list L into the binary file, Employee.DAT?
a) pickle.write(L,f)
b) pickle.write(f, L)
c) pickle.dump(L,F)
d) f=pickle.dump(L)
c) pickle.dump(L,F)
(iii) Write statement, #Line3, to read each record from the binary file Employee.DAT?
a) R = pickle.load(F)
b) pickle.read(r,f)
c) r= pickle.read(f)
d) pickle.load(r,f)
a) R = pickle.load(F)
(iv) Write statement , #Line4, to find employees who are getting salary more than Rs.50000.
a) R[0]
b) R[1]
c) R[2]
d) R[3]
c) R[2]
a) Total/countrec
b) Total/C50K
c) Total/Countrec
d) average(Total)
c) Total/Countrec
55. Anand, a software developer, is asked to help a librarian to find some details of books in his library.
The book information is stored in a binary file Books.DAT. Create two user defined functions/modules:
1. AddBook() to create a binary file called Books.DAT containing Book information – Book name,
Author and Price.
2. ViewBook() to display the name, Author and price of books which are more than Rs.350 in price.
The function should also display the average price of books.
Try to fill the incomplete code to get required information for librarian.
import pickle
def AddBook():
while True:
if Choice in “nN”:
break
Fp.close()
def ViewBook():
Total=0
Count=0
C=0
while True:
try:
Count+=1
Total+=Row[2]
C+=1
except:
break
if C==0:
avgprice=Total/Count
F.close()
AddBook()
ViewBook()
(i) Fill in the blank in Line1, to open the file “Books.DAT” for writing in binary format?
a) Fp= open(“Books.DAT”,’w’)
b) Fp= open(“Books.DAT”,’wb’)
c) Fp= open(“Books.DAT”,’wb+’)
d) Fp= open(“Books.DAT”,’w+’)
b) Fp= open(“Books.DAT”,’wb’)
(ii) Fill in the blank in Line2, to write the list Lst into the binary file, Books.DAT?
a) pickle.write(Lst,fp)
b) pickle.write(fp, Lst)
c) pickle.dump(Lst,Fp)
d) fp=pickle.dump(Lst)
c) pickle.dump(Lst,Fp)
(iii) Fill in the blank in Line3, to open the file “Books.DAT” for reading
a) F= open(“Books.DAT”,’r’)
b) F= open(“Books.DAT”,’r+’)
c) F= open(“Books.DAT”,’wb+’)
d) F= open(“Books.DAT”,’rb’)
d) F= open(“Books.DAT”,’rb’)
a) Row=pickle.load(Fp)
b) Row=pickle.read(Fp)
c) Row=pickle.read(F)
d) Row=pickle.load(F)
d) Row=pickle.load(F)
a) Row[0]
b) Row[1]
c) Row[2]
d) Row[3]
c) Row[2]
56. John, a student of class 12 student wants to complete a search() function to search in a pickled file
Competition.dat.
def search():
______________: # Line -2
while True:
if(_____________): #Line -4
print(rec)
except:
pass
_________________ # Line -5
(i) Fill in the blank in Line1, to open the file “Competition.DAT” for reading in binary format?
a) w
b) r
c) wb
d) rb
d) rb
a) except
b) try
c) handle
d) statement
b) try
a) read(f)
b) readline(f)
c) load(f)
d) load()
c) load(f)
a) rec[0]==1
b) rec[2]==1
c) rec[prize]==1
d) rec[“prize”]==1
b) rec[2]==1
b) f.close()
c) f=close()
d) close(f)
b) f.close()
57. A binary file “Book.DAT” has structure [Bookno, Book_Name, Author, Price].
Ravi, a student of class 12 Computer Science is told to create the file and search for the number of books
of a specific author by completing the blank lines.
import pickle
def createFile():
Book_name=input(“Name :”)
Author = input(“Author: “)
rec=[BookNo,Book_Name,Author,Price]
fobj.close()
def CountRec(Author):
num= 0
try:
while True:
except:
fobj.close()
return num
(i) Fill in the blank in Line1, to open the file “Books.DAT” for writing in binary format?
a) open(“Book.dat”,”ab”)
b) open(“Books.DAT”,’wb’)
c) open(“Books.DAT”,’a’)
d) open(“Books.DAT”,’w+’)
a) open(“Book.dat”,”ab”)
(ii) Fill in the blank in Line2, to write the list rec into the binary file, Books.DAT?
a) pickle.write(rec)
b) pickle.dump(rec,fobj)
c) pickle.dump(fobj,rec)
d) fobj=pickle.dump(rec)
b) pickle.dump(rec,fobj)
(iii) Fill in the blank in Line3, to open the file “Books.DAT” for searching.
a) open(“Book.dat”,”r”)
b) open(“Book.dat”,”rb”)
c) open(“Book.dat”,”wb”)
d) open(“Book.dat”,”ab”)
b) open(“Book.dat”,”rb”)
b) pickle.load(f)
c) pickle.load(fobj)
d) pickle.read(fobj)
c) pickle.load(fobj)
a) rec[0]
b) rec[1]
c) rec[2]
d) rec[3]
c) rec[2]
58. Neha, a software developer is asked to complete a search() function to search in a pickled file
Book.DAT.
Neha wants to complete the code and print details of Book with Book number 123.
def search():
______________: # Line -2
while True:
R = pickle.____________# Line -3
if(_____________): #Line -4
print(R)
except:
pass
_________________ # Line -5
(i) Fill in the blank in Line1, to open the file “Book.DAT” for reading in binary format?
a) w
b) r
c) wb
d) rb
d) rb
a) except
b) try
c) handle
d) statement
b) try
a) read(fp)
b) readline(fp)
c) load(fp)
d) load()
c) load(fp)
a) R[0]==123
b) R[2]==123
c) R[Bookno]==123
d) R[“Bookno”]==123
b) R[2]==123
a) fp.end()
b) fp.close()
c) fp=close()
d) close(fp)
b) fp.close()
59. Neha, a class 12 student is asked to write a binary file, “Admission.DAT”, for entering new admission
student details and review the details when required. She faced some problems in statements and see if
you can fill the missing code.
import pickle
def newadmission():
admnlst=[]
while True:
Stud_name=input(“Name :”)
rec=[AdmnNo,Stud_Name,Fathername,Phone]
if choice in “Nn”:
break
_________________ #Line3 to store data to file
fobj.close()
def getRecords(AdmNo):
result=pickle.load(fobj)
print(rec)
fobj.close()
(i) Identify missing code in Line1 so that file can add more information
a) w
b) r
c) wb
d) rb
c) wb
a) fobj
b) R
c) rec
d) admission
c) rec
(iii) Fill in the necessary function in Line3, to input data to binary file.
a) pickle.dump(“admnlst”,”fobj”)
b) pickle.dump(admnlst,fobj)
c) pickle.dump(“fobj”,“admnlst”)
d) pickle.dump(fobj,admnlst)
b) pickle.dump(admnlst,fobj)
a) open(“Admission.dat”,”read”)
b) open(“Admission.dat”,”r”)
c) open(“Admission.dat”,”rd”)
d) open(“Admission.dat”,”rb”)
d) open(“Admission.dat”,”rb”)
(v) Fill in the blank in Line5 to check for given admission number:
a) AdmnNo
b) “AdmnNo”
c) AdmNo
d) “AdmNo”
c) AdmNo
60. Ananya, a class 12 student is asked to write a binary file, “Fees.DAT”, for entering fee details of
students and review the details when required. She faced some problems in statements and see if you
can fill the missing code.
import pickle
def feeEntry():
Feelst=[]
while True:
rec=[AdmnNo,Stud_Name,Class,Fee]
if choice in “Nn”:
break
fobj.close()
def getRecords(AdmNo):
result=pickle.load(fobj)
print(rec)
fobj.close()
(i) Identify missing code in Line1 so that file can add more information
a) w
b) r
c) wb
d) rb
c) wb
a) fobj
b) R
c) rec
d) admission
c) rec
(iii) Fill in the necessary function in Line3, to input data to binary file.
a) pickle.dump(“Feelst”,”fobj”)
b) pickle.dump(Feelst,fobj)
c) pickle.dump(“fobj”,“Feelst”)
d) pickle.dump(fobj,Feelst)
b) pickle.dump(Feelst,fobj)
a) open(“Fees.dat”,”read”)
b) open(“Fees.dat”,”r”)
c) open(“Fees.dat”,”rd”)
d) open(“Fees.dat”,”rb”)
d) open(“Fees.dat”,”rb”)
(v) Fill in the blank in Line5 to check for given admission number:
a) AdmnNo
b) “AdmnNo”
c) AdmNo
d) “AdmNo”
c) AdmNo