Read and download free pdf of CBSE Class 12 Computer Science Binary Files Worksheet. Download printable Computer Science Class 12 Worksheets in pdf format, CBSE Class 12 Computer Science Binary Files Worksheet has been prepared as per the latest syllabus and exam pattern issued by CBSE, NCERT and KVS. Also download free pdf Computer Science Class 12 Assignments and practice them daily to get better marks in tests and exams for Class 12. Free chapter wise worksheets with answers have been designed by Class 12 teachers as per latest examination pattern
Binary Files Computer Science Worksheet for Class 12
Class 12 Computer Science students should refer to the following printable worksheet in Pdf in Class 12. This test paper with questions and solutions for Class 12 Computer Science will be very useful for tests and exams and help you to score better marks
Class 12 Computer Science Binary Files Worksheet Pdf
Multiple Choice Questions
Question. Which of the following statements is true?
a. load method of pickle module gives error if EOF is reached
b. load method of pickle module returns an empty string is EOF is reached
c. load method of pickle module returns -1 if EOF is reached
d. None of the above
Answer. A
Question. Shylesh is writing python code to append a new record to a binary file ‘salary.dat’ that is storing list objects containing [empid, empname, salary]. Consider the following code written by him.
import pickle
f = open(‘salary.dat’, ‘ab’)
id = input(“Enter employee id : ”)
name = input(“Enter name of employee: ”)
sal = float(input(“Enter salary :”))
record = ___________ #Blank 1
pickle.dump(record,f)
f.close()
Identify the missing part of Blank 1.
a. [id,name,sal]
b. id, name, sal
c. [empid, empname, salary]
d. empid, empname, salary
Answer. A
Question. Which is the valid syntax to write an object onto a binary file opened in the write mode?
a. pickle.dump(<object to be written>, <file handle of open file>)
b. pickle.dump(<file handle of open file>, <object to be written>)
c. dump.pickle(<object>, <file handle>)
d. None of the above
Answer. A
Question. What is the binary file mode associated with “ file must exist, otherwise error will be raised and reading and writing can take place”.
a. wb+
b. w+
c. rb
d. rb+
Answer. D
Question. Rahul is trying to write a tuple t = (10,20,30,40,50) on a binary file notebook.bin. Consider the following code written by him.
import pickle #statement 1
t = (10,20,30,40,50) #statement 2
myfile = open("notebook.bin",'w') #statement 3
pickle.dump(t, myfile) #statement 4
myfile.close()
Which of the following statement contains an error?
a. Statement 1
b. Statement 2
c. Statement 3
d. Statement 4
Answer. C
Question. In which file, no delimiters are used for line and no translations occur?
(a) Text file
(b) Binary file
(c) csv file
(d) None of the above
Answer. B
Question. Choose the file mode used to write data into binary file.
(a) rb
(b) wb
(c) r+
(d) w+
Answer. B
Question. Which of the following function is used to read data from a binary file?
(a) write
(b) load
(c) dump
(d) scan
Answer. B
Question. Dima is trying to read a list l1 from a binary file ‘num’. Consider the following code written by her.
import pickle
f1 = open("num",'rb')
l1=__________________#Statement 1
print(l1)
f1.close()
Identify the missing code in Statement 1.
(a) pickle.load(f1)
(b) pickle.load(l1,f1)
(c) pickle.read(f1)
(d) pickle.dump(l1,f1)
Answer. A
import pickle module, dump() and load() method, read, write/create, search, append and update operations in a binary file
Question. ________ places the file pointer at the specified position in the open file.
a) seek()
b) search()
c) tell()
d) print()
Answer. A
Question. _____________ 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
Answer. A
Question. ___________ of pickle module will pickle the data in the binary file.
a) load()
b) dump()
c) writer()
d) insert()
Answer. B
Question. 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
Answer. A
Question. Which of the following statements is true?
a) pickling creates an object from a sequence of bytes
b) pickling is used for object serialization
c) pickling is used for object deserialization
d) pickling is used to manage all types of files in Python
Answer. B
Question. _______ is the process of reading from a binary file
a) Pickling
b) Unpickling
c) Dumping
d) Loading
Answer. B
Question. _______________ will return the current position of file pointer in the file
a) seek()
b) search()
c) tell()
d) print()
Answer. C
Question. 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
Answer. A
Question. ___________ of pickle module will unpickle the data coming from the binary file.
a) load()
b) dump()
c) writer()
d) insert()
Answer. A
Question. F1.seek(-5,1) will move the file pointer 5 bytes backwards from end of file. State True or False
a) True
b) False
Answer. B
CASE STUDY QUESTIONS (R)
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=[]
fobj=open(“Fees.dat”,”___”) #Line1 to open file for entering data to file
while True:
AdmnNo=int(input(“Admission Number : “))
Stud_name=input(“Name :”)
Class = input(“Enter Class: “)
Fee = int(input(“Enter Fee : “))
rec=[AdmnNo,Stud_Name,Class,Fee]
Feelst.append(______) #Line2 to add a record
choice=input(“Enter more y/n”)
if choice in “Nn”:
break
_________________ #Line3 to store data to file
fobj.close()
def getRecords(AdmNo):
fobj=_______________ #Line4 to open file for searching
result=pickle.load(fobj)
for rec in result:
if rec[0]==______: #Line5 to check for given admission number
print(rec)
fobj.close()
Question. Fill in the blank in Line5 to check for given admission number:
a) AdmnNo
b) “AdmnNo”
c) AdmNo
d) “AdmNo”
Answer. C
Question. Identify missing code in Line1 so that file can add more information
a) w
b) r
c) wb
d) rb
Answer. C
Question. 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)
Answer. B
Question. Fill in the blank in Line4, to read data from file.
a) open(“Fees.dat”,”read”)
b) open(“Fees.dat”,”r”)
c) open(“Fees.dat”,”rd”)
d) open(“Fees.dat”,”rb”)
Answer. D
Question. Identify missing object in Line2
a) fobj
b) R
c) rec
d) admission
Answer. C
Archit wants to create and display a Binary file named “Myfile.DAT”. Complete the missing code to open, create and display the file.
import __________ #Line1
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()
print(” The content of file :”, result)
Question. 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”)
Answer. D
Question. Name the module he should import in Line 1.
a) csv
b) pickle
c) binary
d) bin
Answer. B
Question. 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)
Answer. B
Question. 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)
Answer. D
Question. 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”)
Answer. C
Ritesh wants to perform the following binary file operations, as a part of his assignment, with the help of two user defined functions/modules:
AddEmp() to create a binary file called Employee.DAT containing employee information – employee number, name and salary.
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.
Help him in filling incomplete code.
import pickle
def AddEmp():
#Line1 to open the binary file to write data
while True:
Empno = int(input(“Employee number: :”))
Name = input(“Name : “)
Salary = int(input(“Enter Salary :”))
L = [Empno, Name, Salary]
#Line2 to write the list L into the file
Choice = input(“enter more (y/n): “)
if Choice in “nN”:
break
F.close()
def ViewEmp():
Total=0
Countrec=0
C50K=0
F=open(“Employee.DAT”,”rb”)
while True:
try:
#Line3 to read from the file
Countrec+=1
Total+=R[2]
if _______ > 50000: #Line4
print(R[1],”has salary “,R[2])
C50K+=1
except:
break
if C50K==0:
print(“No employee with salary more than 50000”)
average=______________ #Line5 to find average salary
print(“average Salary = “,average)
AddEmp()
ViewEmp()
Question. 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]
Answer. C
Question. 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+’)
Answer. A
Question. 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)
Answer. A
Question. Write statement , #Line5, to find average salary of employees
a) Total/countrec
b) Total/C50K
c) Total/Countrec
d) average(Total)
Answer. C
Question. 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)
Answer. C
Neha, a software developer is asked to complete a search() function to search in a pickled file Book.DAT.
File contains details of Books [Bookno,Bname, Price] format.
File contains details of 10 Books‟ details
Neha wants to complete the code and print details of Book with Book number 123.
def search():
fp= open(“Book.dat”, _______) # Line -1
______________: # Line -2
while True:
R = pickle.____________# Line -3
if(_____________): #Line -4
print(R)
except:
pass
_________________ # Line -5
Question. Fill in the blank in Line4, to read record from file.
a) R[0]==123
b) R[2]==123
c) R[Bookno]==123
d) R[“Bookno”]==123
Answer. B
Question. 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
Answer. D
Question. Fill in the blank in Line3, to read the records.
a) read(fp)
b) readline(fp)
c) load(fp)
d) load()
Answer. C
Question. Fill in the blank in Line5 to close the file pointer:
a) fp.end()
b) fp.close()
c) fp=close()
d) close(fp)
Answer. B
Question. Fill in the blank in Line2, to handle exceptions in statements
a) except
b) try
c) handle
d) statement
Answer. B
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.
import __________ #Line1
data=[]
rollno=int(input(“Enter Roll number:”))
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”)
Question. 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)
Answer. D
Question. Name the module to import in Line 1.
a) csv
b) pickle
c) binary
d) bin
Answer. B
Question. 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”)
Answer. D
Question. 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
Answer. C
Question. 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)
Answer. B
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():
fobj=_______________ #Line1 to open file for entering data to file
BookNo=int(input(“Book Number : “))
Book_name=input(“Name :”)
Author = input(“Author: “)
Price = int(input(“Price : “))
rec=[BookNo,Book_Name,Author,Price]
_________________ #Line2 to store data to file
fobj.close()
def CountRec(Author):
fobj=_______________ #Line3 to open file for searching
num= 0
try:
while True:
rec=_____________ # Line4 to read a record
if Author==______: #Line5 to check for specific author
num = num + 1
except:
fobj.close()
return num
Question. Fill in the blank in Line4, to read record from file.
a) pickle.read(f)
b) pickle.load(f)
c) pickle.load(fobj)
d) pickle.read(fobj)
Answer. C
Question. 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+’)
Answer. A
Question. 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”)
Answer. B
Question. Fill in the blank in Line5 with suitable expression:
a) rec[0]
b) rec[1]
c) rec[2]
d) rec[3]
Answer. C
Question. 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)
Answer. B
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.
import __________ #Line1
mydata=[]
name=input(“Enter Name:”)
contactno=int(input(“Enter contact number:”))
address=input(“Enter address:”)
mydata=[name,contactno,address]
f1=__________________ #Line2
pickle.________________ #Line 3
f1.close()
f2=___________________ #Line4
result=________________ #Line 5
f2.close()
print(” The content of file :”, result)
Question. 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”)
Answer. D
Question. Name the module he should import in Line 1.
a) csv
b) pickle
c) binary
d) bin
Answer. B
Question. 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)
Answer. B
Question. 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)
Answer. D
Question. 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”)
Answer. C
John, a student of class 12 student wants to complete a search() function to search in a pickled file Competition.dat.
File contains details of prizes in a competition [Rollno,name, prize] format.
File contains details of 10 participants‟ details
Arun has to complete the code and print details of prize 1.
def search():
f = open(“Competition.dat”, _______) # Line -1
______________: # Line -2
while True:
rec = pickle.____________# Line -3
if(_____________): #Line -4
print(rec)
except:
pass
_________________ # Line -5
Question. Fill in the blank in Line4, to read record from file.
a) rec[0]==1
b) rec[2]==1
c) rec[prize]==1
d) rec[“prize”]==1
Answer. B
Question. 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
Answer. D
Question. Fill in the blank in Line3, to read the records.
a) read(f)
b) readline(f)
c) load(f)
d) load()
Answer. C
Question. Fill in the blank in Line5 to close the file pointer:
a) f.end()
b) f.close()
c) f=close()
d) close(f)
Answer. B
Question. Fill in the blank in Line2, to handle exceptions in statements
a) except
b) try
c) handle
d) statement
Answer. B
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:
AddBook() to create a binary file called Books.DAT containing Book information – Book name, Author and Price.
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():
#Line1 to open the binary file to write data
while True:
Name = input(“Book Name : “)
Author= input(“Author Name : “)
Price = int(input(“Enter Book Price :”))
Lst= [Name, Author, Price]
#Line2 to write the list Lst into the file
Choice = input(“enter more (y/n): “)
if Choice in “nN”:
break
Fp.close()
def ViewBook():
Total=0
Count=0
C=0
F=open(________________) #Line3 to open file for reading
while True:
try:
#Line4 to read from the file
Count+=1
Total+=Row[2]
if _______ > 350: #Line5
print(“Price of “,Row[1],”= “,Row[2])
C+=1
except:
break
if C==0:
print(“All books are having price less than 350”)
avgprice=Total/Count
print(“Average Price = “,avgprice)
F.close()
AddBook()
ViewBook()
Question. Fill in the blank in Line4, to read data from file.
a) Row=pickle.load(Fp)
b) Row=pickle.read(Fp)
c) Row=pickle.read(F)
d) Row=pickle.load(F)
Answer. D
Question. 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+’)
Answer. B
Question. 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’)
Answer. D
Question. Fill in the blank in Line5 with suitable expression:
a) Row[0]
b) Row[1]
c) Row[2]
d) Row[3]
Answer. C
Question. 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)
Answer. C
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=[]
fobj=open(“Admission.dat”,”___”) #Line1 to open file for entering data to file
while True:
AdmnNo=int(input(“Admission Number : “)
Stud_name=input(“Name :”)
Fathername = input(“Father’s name: “)
Phone = int(input(“Phone No : “))
rec=[AdmnNo,Stud_Name,Fathername,Phone]
admnlst.append(______) #Line2 to add a record
choice=input(“Enter more y/n”)
if choice in “Nn”:
break
_________________ #Line3 to store data to file
fobj.close()
def getRecords(AdmNo):
fobj=_______________ #Line4 to open file for searching
result=pickle.load(fobj)
for rec in result:
if rec[0]==______: #Line5 to check for given admission number
print(rec)
fobj.close()
Question. Fill in the blank in Line4, to read data from file.
a) open(“Admission.dat”,”read”)
b) open(“Admission.dat”,”r”)
c) open(“Admission.dat”,”rd”)
d) open(“Admission.dat”,”rb”)
Answer. D
Question. Identify missing code in Line1 so that file can add more information
a) w
b) r
c) wb
d) rb
Answer. C
Question. 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)
Answer. B
Question. Fill in the blank in Line5 to check for given admission number:
a) AdmnNo
b) “AdmnNo”
c) AdmNo
d) “AdmNo”
Answer. C
Question. Identify missing object in Line2
a) fobj
b) R
c) rec
d) admission
Answer. C
Binary Files CBSE Class 12 Computer Science Worksheet
The above practice worksheet for Binary Files has been designed as per the current syllabus for Class 12 Computer Science released by CBSE. Students studying in Class 12 can easily download in Pdf format and practice the questions and answers given in the above practice worksheet for Class 12 Computer Science on a daily basis. All the latest practice worksheets with solutions have been developed for Computer Science by referring to the most important and regularly asked topics that the students should learn and practice to get better scores in their examinations. Studiestoday is the best portal for Printable Worksheets for Class 12 Computer Science students to get all the latest study material free of cost. Teachers of studiestoday have referred to the NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 worksheet. After solving the questions given in the practice sheet which have been developed as per the latest course books also refer to the NCERT solutions for Class 12 Computer Science designed by our teachers. After solving these you should also refer to Class 12 Computer Science MCQ Test for the same chapter. We have also provided a lot of other Worksheets for Class 12 Computer Science which you can use to further make yourself better in Computer Science.
You can download the CBSE Practice worksheets for Class 12 Computer Science Binary Files for the latest session from StudiesToday.com
Yes, the Practice worksheets issued for Binary Files Class 12 Computer Science have been made available here for the latest academic session
There is no charge for the Practice worksheets for Class 12 CBSE Computer Science Binary Files you can download everything free
Regular revision of practice worksheets given on studiestoday for Class 12 subject Computer Science Binary Files can help you to score better marks in exams
Yes, studiestoday.com provides all the latest Class 12 Computer Science Binary Files test practice sheets with answers based on the latest books for the current academic session