Q1.
Write a Python program to write the following list of names into a binary file named
names.dat.
names = ['Aman', 'Riya', 'Kabir', 'Tina']
Q2. Write a Python function countEvenNumbers() that reads integers from a binary file
numbers.dat 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 student.dat.
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
data.dat line by line.
Q6. Write a complete Python program to:
● Create a binary file employee.dat 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 student.dat 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 books.dat (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 employee.dat. The
program should accept an empid from the user and increase the salary by 10% if found.
Q10. You are given a binary file marks.dat 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 cities.dat.
Q12. Define a function read_last_record() that reads and displays only the last record from
the binary file products.dat, which contains a list of product dictionaries.
Q13. Write a function search_name() that accepts a name and displays all records from
student.dat where the name matches.
Q14. What exception must be handled while reading from a binary file using pickle.load() 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 library.dat.
● Then display all books by a given author.
Q17. Write a Python program to:
● Store employee records (ID, name, department, salary) in emp.dat.
● 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 product.dat. Assume each record is a dictionary.
Q19. Write a Python program that:
● Reads all student records from student.dat
● Updates marks to 100 for all students whose name starts with ‘A’
Q20. Write a program to copy all records from employee.dat to manager.dat if the department
is ‘Management’.