[go: up one dir, main page]

0% found this document useful (0 votes)
102 views1 page

Binary File

The document outlines various tasks involving the creation and manipulation of binary files in Python, including employee records, flight information, sports data, book records, patient details, plant records, customer orders, and candidate management. Each task specifies functions to add, display, count, and modify records based on certain criteria. The document serves as a guide for implementing file handling and data management in Python applications.

Uploaded by

Hardik Aggarwal
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)
102 views1 page

Binary File

The document outlines various tasks involving the creation and manipulation of binary files in Python, including employee records, flight information, sports data, book records, patient details, plant records, customer orders, and candidate management. Each task specifies functions to add, display, count, and modify records based on certain criteria. The document serves as a guide for implementing file handling and data management in Python applications.

Uploaded by

Hardik Aggarwal
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/ 1

Binary File

1. Given a binary file employee.dat, created using dictionary object having keys: (empcode, name, and
salary)
Write a python function that add one more record at the end of file.
Write a python function that display all employee records whose salary is more that 30000
2. Write a Python script to create a binary file “Flight.dat” containing information : FlightNum ,
NoOfSeats, StartingPoint and Destination.
 Display all flights with Destination =”Delhi”
 Count all flights with NoOfSeats more than 150.
 Display the details of flight with given FlightNo.
 Change the Destination to “Mumbai” for flightNum= “A102”
3. Consider a file, SPORT.DAT, containing records of the following structure:
[SportName, TeamName, No_Players]
Write a function, copyData(), that reads contents from the file SPORT.DAT
and copies the records with Sport name as “Basket Ball” to the file named BASKET.DAT. The function
should return the total number of records copied to the file BASKET.DAT
4. 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 .
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”
5. A binary file “PATIENTS.dat” has structure [PID, NAME,DISEASE].
Write the definition of a function countrec() in Python that would read contents of the file
“PATIENTS.dat” and display the details of those patients who have the DISEASE as ‘COVID-19’. The
function should also display the total number of such patients whose DISEASE is ‘COVID-19’.
6. A binary file “PLANTS.dat” has structure [ID, NAME, PRICE].
Write the definition of a function WRITEREC() in Python, to input data for records from the user and
write them to the file PLANTS.dat.
Write the definition of a function SHOWHIGH() in Python, which reads the records of PLANTS.dat and
displays those records for which the PRICE is more than 500.
7. Simran is developing a Python program to manage customer orders for an online store. Order data
(order_id, customer_name, order_date, total_amount) is stored in a binary file named "Orders.dat".
Each order is represented as a tuple. Help Simran complete the following tasks:
i. Write a function `add_order()` to input order details from the user (order_id, customer_name,
order_date, total_amount) and store them in "Orders.dat". The program should allow adding
multiple orders until the user chooses to stop.
ii. Write a function `update_order_amount()` to modify the `total_amount` for orders placed. The
function should increase the `total_amount` of each qualifying order by 10%.
iii. Write a function `count_high_value_orders()` to count and display the number of orders with a
`total_amount` greater than 1000.
8. Gyandev is manager in an educational institute. He needs to manage the records of various
candidates. For this, he wants the following information of each candidate to be stored in a list: -
Candidate_id – integer - Cadidate_name – string - Class – string - Status – string You, as a
programmer of the institute, have been assigned to do this job for Gyandev.
i. Write a function addBin() to input the data of a candidate, create a list of it and append it in a
binary file named “Students.dat”.
ii. Write a function promoteBin() to change the status to “passed out” for those students whose class
is “XII”
iii. (Write a function activeBin() to read the data from the binary file and display the data of all those
candidates who are not “passed out”.

You might also like