Data File Handling-BinaryFile
Data File Handling-BinaryFile
Data File Handling-BinaryFile
Q.No Questions
1 A binary file “STUDENT.DAT” has structure (admission_number, Name, Percentage). Write afunction
countrec() in Python that would read contents of the file “STUDENT.DAT” anddisplay the details of
those students whose percentage is above 75. Also display number ofstudents scoring above 75%
2 A binary file “Book.dat” has structure: [BookNo, Book_Name, Author,Price]. i. Write a user defined
function CreateFile() to input data for a recordand add to Book.dat. 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 “Book.dat”
3 A binary file “Toy.dat” has structure [TID, Toy, Status, MRP]. i. Write a user defined function
CreateFile() to input data for a record and add to "Toy.dat" ii. Write a function OnOffer() in Python to
display the detail of those Toys, which has status as “ON OFFER” from "Toy.dat" 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 CINEMA.DAT, 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(“phonebook.dat”,’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 blocked.dat and unblocked.dat binary files
(Statement 2 and 3)
(iii) Which statement should Vaishnavi use in statement 4 to read the data from thebinary file,
phonebook.dat
(iv) Which statement should Vaishnavi use in statement 5 and 6 to write data to theblocked.dat and
unblocked.dat