CBSE Class 12 Computer Science File Handling Worksheet Set B

Access the latest CBSE Class 12 Computer Science File Handling Worksheet Set B. We have provided free printable Class 12 Computer Science worksheets in PDF format, specifically designed for File Handling. These practice sets are prepared by expert teachers following the 2025-26 syllabus and exam patterns issued by CBSE, NCERT, and KVS.

File Handling Computer Science Practice Worksheet for Class 12

Students should use these Class 12 Computer Science chapter-wise worksheets for daily practice to improve their conceptual understanding. This detailed test papers include important questions and solutions for File Handling, to help you prepare for school tests and final examination. Regular practice of these Class 12 Computer Science questions will help improve your problem-solving speed and exam accuracy for the 2026 session.

Download Class 12 Computer Science File Handling Worksheet PDF

Question. Which function is used to change the position of the File Handle to a given specific position.
a) seek()
b) read()
c) tail()
d) write()

Answer : A

Question. How do you change the file position to an offset value from the start?
a) fp.seek(offset, 0)
b) fp.seek(offset, 1)
c) fp.seek(offset, 2)
d) none of the mentioned

Answer : A

Question. Which is the correct statement with respect of seek() function?
a) 0: sets the reference point at the beginning of the file
b) 1: sets the reference point at the current file position
c) 2: sets the reference point at the end of the file
d) All of these

Answer : D

Question. Which of the following statements correctly explain the function of seek() method?
a) tell the current position within the file.
b) indicate that the next read or write occurs from that position in a file.
c) determine if you can move the file position or not.
d) move the current file position to a different location at a defined offset.

Answer : D

Question. What does the <readlines()> method returns?
a) str
b) a list of lines
c) list of single characters
d) list of integers

Answer : B

Question. Which of the following functions can be used to check if a file “logo” exists?
a) os.path.isFile(logo)
b) os.path.exists(logo)
c) os.path.isfile(logo)
d) os.isFile(logo)

Answer : C

Question. Seek() function with negative offset only works when file is opened in ——– mode.
a) read mode
b) write mode
c) binary mode
d) All of these

Answer : C

Question. What happens if no arguments are passed to the seek function?
a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error

Answer : D

Question. What is the use of seek() method in files()?
a) sets the file’s current position at the offset
b) sets the file’s previous position at the offset
c) sets the file’s current position within the file
d) none of the mentioned

Answer : A

Question. To read the next line of the file from a file object fobj, we use:
a) fobj.read(2)
b) fobj.read()
c) fobj.readline()
d) fobj.readlines()

Answer : C

Question. Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?
a) file.read(n)
b) n = file.read()
c) file.readline(n)
d) file.readlines()

Answer : A

Question. What is the use of seek() method in files?
a) sets the file‟s current position at the offset
b) sets the file‟s previous position at the offset
c) sets the file‟s current position within the file
d) none of the mentioned

Answer : A

Question. Which of the following statements correctly explain the function of tell() method?
a) tells the current position within the file.
b) indicates that the next read or write will occur at that many bytes from the beginning of the file.
c) move the current file position to a different location.
d) it changes the file position only if allowed to do so else returns an error.

Answer : A, B

Question. Which of the following command is used to open a file “c:\temp.txt” in append-mode?
a) outfile = open(“c:/temp.txt”, “a”)
b) outfile = open(“c:\\temp.txt”, “rw”)
c) outfile = open(“c:\temp.txt”, “w+”)
d) outfile = open(“c:\\temp.txt”, “r+”)

Answer : A

Question. How do you get the current position within the file?
a) fp.seek()
b) fp.tell()
c) fp.loc
d) fp.pos

Answer : B

Question. Which of the following command is used to open a file “c:\temp.txt” in read-mode only?
a) infile = open(“c:\temp.txt”, “r”)
b) infile = open(“c:\\temp.txt”, “r”)
c) infile = open(file = “c:\temp.txt”, “r+”)
d) infile = open(file = “c:\\temp.txt”, “r+”)

Answer : B

Question. If we open the file in read mode then the initial value of tell() is
a) -1
b) 0
c) 1
d) End of the file

Answer : A

Question. What happens if no arguments are passed to the seek function?
a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error

Answer : D

 
1. Fill in the blanks.
 
i. ..................... format is a text format, accessible to all applications across several platforms.
 
ii. ..................... method is used for random access of data in a CSV file.
 
iii. ..................... method of pickle module is used to write an object into binary file.
 
iv. ..................... method of pickle module is used to read data from a binary file.
 
v. ..................... is a string method that joins all values of each row with comma separator in CSV.
 
vi. ..................... object contains the number of the current line in a CSV file.
 
2. State whether the following statements are True or False.
 
i. The type of operation that can be performed on a file depends upon the file mode in which it is opened.
 
ii. Functions readline() and readlines() are essentially the same.
 
iii. Comma is the default delimiter for a CSV file.
 
iv. tell() method of Python tells us the current position within the file.
 
v. The offset argument to seek() method indicates the number of bytes to be moved.
 
vi. If the offset value is set to 2, beginning of the file would be taken as seek position.
 
3. Multiple Choice Questions (MCQs)
 
(a) Which of the following is not a valid mode to open a file?
 
(i) ab   (ii) rw   (iii) r+   (iv) w+
 
(b) Which statement is used to change the file position to an offset value from the start?
 
(i) fp.seek(offset, 0) (ii) fp.seek(offset, 1)
 
(iii) fp.seek(offset, 2) (iv) None of the above
 
(c) The difference between r+ and w+ modes is expressed as?
 
(i) No difference (ii) In r+ mode, the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
 
(iii) In w+ mode, the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
 
(iv) Depends on the operating system
 
(d) What does CSV stand for?
 
(i) Cursor Separated Variables    (ii) Comma Separated Values
 
(iii) Cursor Separated Values     (iv) Cursor Separated Version
 
(e) Which module is used for working with CSV files in Python?
 
(i) random   (ii) statistics   (iii) csv   (iv) math
 
(f) Which of the following modes is used for both writing and reading from a binary file?
 
(i) wb+    (ii) w    (iii) wb   (iv) w+
 
(g) Which statement is used to retrieve the current position within the file?
 
(i) fp.seek()   (ii) fp.tell()   (iii) fp.loc   (iv) fp.pos
 
(h) What happens if no arguments are passed to the seek() method?
 
(i) file position is set to the start of file
 
(ii) file position is set to the end of file
 
(iii) file position remains unchanged
 
(iv) results in an error
 
(i) Which of the following modes will refer to binary data?
 
(i) r   (ii) w   (iii) +   (iv) b
 
(j) Every record in a CSV file is stored in reader object in the form of a list using which method?
 
(i) writer()   (ii) append()   (iii) reader()   (iv) list()
 
4. Consider the following code:
 
f = open('test', 'w+')
f.write('0123456789abcdef')
f.close()
f=open('test','rb')
f.seek(-3,2) //Statement 1
print(f.read(2)) //Statement 2
f.close()
Explain statement 1 and give output of statement 2.
5. What is the output of the following code :
fh = open("test.txt", "r")
Size = len(fh.read())
print(fh.read(5))
 
6. Give the output of the following snippet:
 
import pickle
list1, list2 = [2, 3, 4, 5, 6, 7, 8, 9, 10], []
for i in list1:
if (i%2==0 and i%4==0):
list2.append(i)
f = open("bin.dat","wb")
pickle.dump(list2, f)
f.close()
f = open("bin.dat", "rb")
data = pickle.load(f)
f.close()
for i in data:
print(i)
 
7. Following is the structure of each record in a data file named as
 
”PRODUCT.DAT”.
{"prod_code":value, "prod_desc":value, "stock":value}
The values for prod_code and prod_desc are strings, and the value for stock is an integer. Write a function in PYTHON to update the file with a new value of stock.
The stock and the prod_code, whose stock is to be updated, are to be input during the execution of the function.
 
8. Given a binary file “STUDENT.DAT”, containing records of the following type:
 
[S_Admno, S_Name, Percentage]
Where these three values are:
S_Admno – Admission Number of student (string)
S_Name – Name of student (string)
Percentage – Marks percentage of student (float)
Write a function in PYTHON that would read contents of the file
“STUDENT.DAT” and display the details of those students whose percentage is above 75.
 
9. Assuming the tuple Vehicle as follows:
 
( vehicletype, no_of_wheels)
Where vehicletype is a string and no_of_wheels is an integer.
Write a function showfile() to read all the records present in an already existing binary file SPEED.DAT and display them on the screen, also count the number of records present in the file.
 
10. Write a function in PYTHON to search for a BookNo from a binary file
 
“BOOK.DAT”, assuming the binary file is containing the records of the following type:
{"BookNo":value, "Book_name":value}
Assume that BookNo is an integer.
 
11. Assuming that a binary file VINTAGE.DAT contains records of the following type [VNO, VDesc, price].
 
Write a function in PYTHON to read the data VINTAGE.DAT and display those vintage vehicles, which are priced between 200000 and 250000.
 
12. Write a function in PYTHON to delete a laptop from a binary file
“LAPTOP.DAT” containing the records of following type.
[ModelNo, RAM, HDD, Details]
where ModelNo, RAM, HDD are integers and Details is a string. The user should enter the model number and the function should delete the details of the laptop from the file.
 
13. Write a menu-driven program to perform all the basic operations using dictionary on student binary file such as
 
i. Inserting records
ii. Reading all records & displaying
iii. Updating record based on given roll number
iv. Searching record based on given marks
v. Deleting a record based on given name
Structure of student dictionary :
{“ ROLLNO”: roll,”NAME”:name,”MARKS”:marks}
 
14. What are the advantages of CSV file formats?
 
15. Write a menu-driven program implementing user-defined functions to perform different functions on a csv file “student” such as:
 
(a) Write a single record to csv
(b) Write all the records in one single go onto the csv.
(c) Display the contents of the csv file.

 

Please click on below link to download CBSE Class 12 Computer Science File Handling Worksheet Set B

File Handling CBSE Class 12 Computer Science Worksheet

Students can use the File Handling practice sheet provided above to prepare for their upcoming school tests. This solved questions and answers follow the latest CBSE syllabus for Class 12 Computer Science. You can easily download the PDF format and solve these questions every day to improve your marks. Our expert teachers have made these from the most important topics that are always asked in your exams to help you get more marks in exams.

NCERT Based Questions and Solutions for File Handling

Our expert team has used the official NCERT book for Class 12 Computer Science to create this practice material for students. After solving the questions our teachers have also suggested to study the NCERT solutions  which will help you to understand the best way to solve problems in Computer Science. You can get all this study material for free on studiestoday.com.

Extra Practice for Computer Science

To get the best results in Class 12, students should try the Computer Science MCQ Test for this chapter. We have also provided printable assignments for Class 12 Computer Science on our website. Regular practice will help you feel more confident and get higher marks in CBSE examinations.

Where can I download latest CBSE Practice worksheets for Class 12 Computer Science File Handling

You can download the CBSE Practice worksheets for Class 12 Computer Science File Handling for the latest session from StudiesToday.com

Are the Class 12 Computer Science File Handling Practice worksheets available for the latest session

Yes, the Practice worksheets issued for File Handling Class 12 Computer Science have been made available here for the latest academic session

Is there any charge for the Practice worksheets for Class 12 Computer Science File Handling

There is no charge for the Practice worksheets for Class 12 CBSE Computer Science File Handling you can download everything free

How can I improve my scores by solving questions given in Practice worksheets in File Handling Class 12 Computer Science

Regular revision of practice worksheets given on studiestoday for Class 12 subject Computer Science File Handling can help you to score better marks in exams

Are there any websites that offer free Practice test papers for Class 12 Computer Science File Handling

Yes, studiestoday.com provides all the latest Class 12 Computer Science File Handling test practice sheets with answers based on the latest books for the current academic session