0% found this document useful (0 votes)
81 views

Binary File Worksheet2

Uploaded by

notneedtome
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Binary File Worksheet2

Uploaded by

notneedtome
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1 Mark Questions

1. The process of converting byte stream back to the original structure is known as
a. Picklingb. b. Unpickling c. Packing d. Zipping
2. Which file mode is used to handle binary file for reading.
a. rb b. rw c. r d. w
3. 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. Characters translation is not required d. Every line ends with new line character ‘\n’
4. Which one of the following is correct statement?
a. import – pickle b. pickle import c. import pickle d. All the above
5. Which of the following file mode opens a file for append 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+
6. Which of the following file mode opens a file for reading and writing both as well as
overwrite the
existing file if the file exists otherwise creates a new file?
a. w b. wb+ c. wb d. rwb
7. Mr Sharma 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 sharma_list.dat, and file object as f. Which of the following can be the
correct
statement for him?
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)
8. Every file has its own identity associated with it. This is known as:
a. icon b. extension c. format d. file type
9. EOL in a file stands for :
a. End of Lines b. End of Line c. End of List d. End of Location
10. Which of the following file types allows you to store large data files in the computer
memory?
a. Binary Files b. Text Files c. CSV Files d. None of these
2 Marks Questions
1. Write a program in python to write and read structure, dictionary to the binary file.
2. BINARY file is unreadable and open and close through a function only so what are the
advantages of
using binary file
3. Write a statement to open a binary file name sample.dat in read mode and the file sample.dat
is placed in
a folder ( name school) existing in c drive.
4. When do you think text files should be preferred over binary files?
5. Consider a binary file employee.dat containing details such as empno:ename:salary (separator
':') write a
python function to display details of those employees who are earning between 20000 and
30000(both
values inclusive)
6. Differentiate between pickle.load() and pickle.dump() methods with suitable examples.
7. A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].Write a user
defined
function CreateFile() to input data for a record and add to Book.dat
8. 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.
9. A binary file “Store.dat” has structure [ItemNo, Item_Name, Company, Price]. Write a
function
CountRec(Company) in Python which accepts the Company name as parameter and count and
return
number of Items by the given Company are stored in the binary file “Store.dat”.
10. A binary file “Store.dat” has structure [ItemNo, Item_Name, Company, Price]. Write a
function
AddRecord() which accepts a List of the record [ItemNo, Item_Name, Company, Price] and
appends in the
binary file “Store.Dat”.
3 Marks Questions
1. A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].
i. Write a user defined function CreateFile() to input data for a record and add to “Book.dat” .
ii. Write a function CountRec(Author) in Python which accepts the Author name as parameter
and count
and return number of books by the given Author are stored in the binary file “Book.dat”
2. A binary file “SCHOOL.DAT” has structure [Roll_Num, Name, Percentage]
i) Write a function Count_Rec() in Python that would read contents of the file “SCHOOL.DAT”
and
display the details of those students whose percentage is below 33.
ii) Write a function Disp_Rec(alphabet) in Python that would read contents of the file
“SCHOOL.DAT”
and display the details of those students whose name begins with the alphabet as passed as
parameter to the
function.
3. A binary file “STOCK.DAT” has structure [ITEMID, ITEMNAME, QUANTITY, PRICE].
Write a user
defined function MakeFile( )to input data for a record and add to Book.dat.
4. Write a function GetPrice(ITEMID) in Python which accepts the ITEMID as parameter and
returns
PRICE of the Item stored in Binary file STOCK.DAT.
5. A binary file “EMPLOYEE.DAT” has structure (EMPID, EMPNAME, SALARY). Write a
function
CountRec( ) in Python that would read contents of the file “EMPLOYEE.DAT” and display the
details of
those Employees whose Salary is above 20000.
6. A binary file “EMPLOYEE.DAT” has structure (EMPID, EMPNAME, SALARY). Write a
function to
display number of employees having Salary more than 20000.
7. A binary file named “EMP.dat” has some records of the structure [EmpNo, EName, Post,
Salary], Write
a user-defined function named NewEmp() to input the details of a new employee from the user
and store it
in EMP.dat.
8. Write a user-defined function named SumSalary(Post) that will accept an argument the post of
employees & read the contents of EMP.dat and calculate the SUM of salary of all employees of
that Post.
9. A binary file named “TEST.dat” has some records of the structure [TestId, Subject,
MaxMarks,
ScoredMarks] Write a function in Python named DisplayAvgMarks(Sub) that will accept a
subject as an
argument and read the contents of TEST.dat.
10. Write a python program to search and display the record of the student from a binary file
“Student.dat”
containing students records (Rollno, Name and Marks). Roll number of the student to be
searched will be
entered by the user.
5 Marks Questions
1. A binary file “student.dat” has structure [rollno, name, marks].
i. Write a user defined function insertRec() to input data for a student and add to student.dat.
ii. Write a function searchRollNo(r) in Python which accepts the student’s rollno as parameter
and searches
the record in the file “student.dat” and shows the details of student i.e. rollno, name and marks (if
found)
otherwise shows the message as ‘No record found’.
2. Write a python program to create binary file dvd.dat and write 10 records in it:
Dvd id,dvd name,qty,price
Display those dvd details whose dvd price is more than 25.

You might also like