0% found this document useful (0 votes)
210 views3 pages

Python Binary File Operations Guide

The document contains a series of programming tasks related to binary file handling in Python. It includes writing and reading binary files, counting even numbers, storing student records, and updating employee salaries. Additionally, it covers differences between file modes, exception handling, and data manipulation for various scenarios.

Uploaded by

Smritituku Datta
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)
210 views3 pages

Python Binary File Operations Guide

The document contains a series of programming tasks related to binary file handling in Python. It includes writing and reading binary files, counting even numbers, storing student records, and updating employee salaries. Additionally, it covers differences between file modes, exception handling, and data manipulation for various scenarios.

Uploaded by

Smritituku Datta
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

Q1.

Write a Python program to write the following list of names into a binary file named
[Link].

names = ['Aman', 'Riya', 'Kabir', 'Tina']

Q2. Write a Python function countEvenNumbers() that reads integers from a binary file
[Link] and returns the count of even numbers stored in it.

Q3. Consider the following list of student dictionaries. Write a program to store this data into a
binary file [Link].

students = [
{'roll': 1, 'name': 'Arjun', 'marks': 87},
{'roll': 2, 'name': 'Neha', 'marks': 92}
]

Q4. What is the difference between wb and ab modes in binary file handling in Python? Give
examples.

Q5. Write a function readFile() that reads and displays the contents of a binary file named
[Link] line by line.

Q6. Write a complete Python program to:

● Create a binary file [Link] to store employee records (empid, name, salary).

● Accept details from the user.

● Store the details using pickle.

Q7. Write a program to search and display the record of a student having roll number 102
from a binary file [Link] which stores dictionaries in the format:

{'roll': int, 'name': str, 'marks': float}


Q8. Write a Python program to:

● Read all records from the binary file [Link] (containing dictionaries of book details:
bookid, title, price).

● Create another binary file expensive_books.dat containing only those books with price
> 500.

Q9. Write a Python program to update the salary of an employee in the file [Link]. The
program should accept an empid from the user and increase the salary by 10% if found.

Q10. You are given a binary file [Link] containing marks (integers) of students. Write a
function calculate_average() to compute and return the average marks of all students stored
in the file.

Q11. Write a Python program to append a list of city names to an existing binary file [Link].

Q12. Define a function read_last_record() that reads and displays only the last record from
the binary file [Link], which contains a list of product dictionaries.

Q13. Write a function search_name() that accepts a name and displays all records from
[Link] where the name matches.

Q14. What exception must be handled while reading from a binary file using [Link]() in a
loop? Why?

Q15. Differentiate between text and binary file handling with one example each.
Q16. Create a Python program to:

● Accept data for multiple books: book ID, title, author.

● Save the data into [Link].

● Then display all books by a given author.

Q17. Write a Python program to:

● Store employee records (ID, name, department, salary) in [Link].

● Display all employees whose salary is more than Rs. 60,000.

Q18. Write a program to count how many times a product with price > 1000 appears in a
binary file [Link]. Assume each record is a dictionary.

Q19. Write a Python program that:

● Reads all student records from [Link]

● Updates marks to 100 for all students whose name starts with ‘A’

Q20. Write a program to copy all records from [Link] to [Link] if the department
is ‘Management’.

You might also like