๐ Section A: 1 Mark Questions (Objective Type)
1. Which file mode is used to append data to an existing text file?
2. What will be the output of the following code?
f = open("data.txt", "r") print(f.readline()) f.close()
3. Name the module used for binary file handling in Python.
4. What is the purpose of the seek()
function in file handling?
5. Which method is used to write a row in a CSV file using a dictionary?
6. What will pickle.load(f)
return when it reaches the end of file?
7. In CSV handling, what does the DictReader
class return for each row?
8. Write the full form of CSV.
9. Which error is commonly handled while reading from a binary file?
10. State True or False: readlines()
returns all lines of a text file as a list of strings.
✍️ Section B: 2 Marks Questions (Very Short Answer)
11. Differentiate between a text file and a binary file. Give one example of each.
12. Write a Python statement to open a file named log.txt
in read mode.
13. What is the purpose of using newline=""
while opening a CSV file in write mode?
14. Mention two differences between csv.reader()
and csv.DictReader()
.
15. How is data written to a binary file using the pickle
module?
16. Name any two methods to read content from a text file in Python.
17. Write a short note on pickling in Python.
18. Define the term serialization in context of binary file handling.
19. How are records written and read from a CSV file using DictWriter()
and DictReader()
?
๐ป Section C: 3 Marks Questions (Short Programming / Output-Based)
20. Write a Python program to:
– Create a file data.txt
– Write two lines of text into it.
21. Given a binary file marks.dat
containing a list of student records in the form [roll, name, marks]
, write a program to read and display all records.
22. Write a Python program to:
– Open students.csv
– Read and print names of students who scored more than 80.
23. Write a program to copy contents of one text file to another.
24. A CSV file contains product data (ProductID, Name, Price
). Write a Python program to:
– Read the file
– Print names of products costing more than ₹100.
๐ง Section D: 5 Marks Questions (Case-Based / Extended Programming)
25. Case Study – Binary File Handling
A binary file employee.dat
contains records of employees in the format [ID, Name, Salary]
.
Write a Python program to:
- Read all records.
- Increase salary by 10% for employees earning less than ₹25,000.
- Save the updated data in a new file
updated_employee.dat
.
26. Case Study – CSV File Handling
You are provided a CSV file sales.csv
with the following data:
ID, Name, Sales
101, Ajay, 15000
102, Sunita, 8000
103, Riya, 22000
Write a program to:
- Display names of salespersons with sales greater than ₹10,000.
- Count the number of people whose sales were below ₹10,000.