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

Asm 19683

Uploaded by

dhruvtiwarix2910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Asm 19683

Uploaded by

dhruvtiwarix2910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ASSIGNMENT ON BINARY FILE

1)Which of the following statement is incorrect in the context of binary files?

a. Information is stored in the same format in which the information is held in memory.

b. No character translation takes place

c. Every line ends with a new line character

d. pickle module is used for reading and writing

2) Which of the following statement opens a binary file record.bin in write mode and writes data from a list lst1 =
[1,2,3,4] on the binary file?

a. with open('record.bin','wb') as myfile:


pickle.dump(lst1,myfile)
b. with open('record.bin','wb') as myfile:
pickle.dump(myfile,lst1)
c. with open('record.bin','wb+') as myfile:
pickle.dump(myfile,lst1)
d. with open('record.bin','ab') as myfile:
pickle.dump(myfile,lst1)
3)Write a Program in Python that defines and calls the following user defined functions:
(i) ADD() – To accept and add data of an employee to a binary file ‘record.dat’. Each record consists of a list with
field elements as empid, name and salary to store employee id, employee name and employee salary respectively.
(ii) COUNTR() – To count the number of records present in the binary file named ‘record.dat’.
4) Write a Program in Python that defines and calls the following user defined functions:
(i) add() – To accept and add data of an employee to a binary file ‘furdata.dat. Each record consists of a list with field
elements as fid, fname and fprice to store furniture id, furniture name and furniture price respectively.
(ii) search()- To display the records of the furniture whose price is more than 10000.
5) Write a user define function write_bin( ) to create a binary file cust.dat containing c_no,c_name,qty and price
The function accept no ,name,quatity and price. Thereafter it display the message ‘Quantity less than 10……..cannot
save’ otherwise function calculate the amount as price*qty and then write the record in the form of a list into binary
file.
6) Write a program to read a binary file student.dat containing rollno, name,marks and display the details of those
student who have more than 75 marks .
7) Write a program to increase the salary by 2000 of those employee having same empno entered by user.
8) A binary file “book.dat” has structure [bookno,bookname,author,price]
(i) write a 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 given author are stored in binary file.
9)Write a program to write list of states in binary file and display the name of all the state starts from alphabet ‘m’.
10) Aman is a Python programmer. He has written a code and created a binary file record.dat with employeeid,
ename and salary. The file contains 10 records. He now has to update a record based on the employee id entered by
the user and update the salary. The updated record is then to be written in the file temp.dat. The records which are
not to be updated also have to be written to the file temp.dat. If the employee id is not found, an appropriate
message should to be displayed.

You might also like