VELAMMAL BODHI CAMPUS – COIMBATORE
Data File Handling – Worksheet –Binary File
XII - Computer Science
[Link] Questions
1 A binary file “[Link]” has structure (admission_number, Name, Percentage). Write afunction
countrec() in Python that would read contents of the file “[Link]” anddisplay the details of
those students whose percentage is above 75. Also display number ofstudents scoring above 75%
2 A binary file “[Link]” has structure: [BookNo, Book_Name, Author,Price]. i. Write a user defined
function CreateFile() to input data for a recordand add to [Link]. ii. Write a function CountRec
(Author) in Python which accepts theAuthor name as parameter and count and return number of books
bythe given Author are stored in the binary file “[Link]”
3 A binary file “[Link]” has structure [TID, Toy, Status, MRP]. i. Write a user defined function
CreateFile() to input data for a record and add to "[Link]" ii. Write a function OnOffer() in Python to
display the detail of those Toys, which has status as “ON OFFER” from "[Link]" file.
4 Considering the following definition of dictionary MULTIPLEX, write a method in python to search and
display all the content in a pickled file [Link], where MTYPE key of the dictionary is matching
with the value "Comedy". MULTIPLEX = {'MNO': _____, 'MNAME": _____, 'MTYPE': _____}
5 As a Python expert, help to Vaishnavi to complete the following code based on the requirement given
above:
import ______________ #Statement 1
def shift_contact( ):
fin = open(“[Link]”,’rb’)
fblock = open( ) #Statement 2
funblock = open( ___________________ ) #Statement 3
while True :
try:
rec = __________________ # Statement 4
if rec*“blocked”+ == ‘Y’:
pickle___________________ #Statement 5
if rec*“blocked”+ == ‘N’:
pickle__________________ # Statement 6
except:
break
(i) Which module should be imported in the program? (Statement 1)
(ii) Write the correct statement required to open a [Link] and [Link] binary files
(Statement 2 and 3)
(iii) Which statement should Vaishnavi use in statement 4 to read the data from thebinary file,
[Link]
(iv) Which statement should Vaishnavi use in statement 5 and 6 to write data to [Link] and
[Link]