CBSE Class 12 Computer Science File Handling Worksheet Set 02

Class 12 Computer Science Practice Set: File Handling

Review targeted practice sets for Class 12 Computer Science File Handling. Built according to official educational guidelines for the 2026-27 academic year, these downloadable worksheets support daily revision and core concept reinforcement.

Download File Handling Worksheet PDF

View or download the dedicated File Handling practice resource below. Engaging with these objective and subjective questions daily ensures continuous academic progress and mastery of the 2026-27 curriculum.

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

Download CBSE Practice Material: Class 12 Computer Science File Handling

Download Practice Sheet: File Handling (Class 12 Computer Science)

Access structured practice worksheets for File Handling designed in alignment with the latest CBSE curriculum for Class 12 Computer Science. These printable problem sets help students build accuracy and prepare effectively for school tests.

Concept Clarification for File Handling

Cross-reference your completed exercises with comprehensive NCERT solutions for Class 12 Computer Science to ensure absolute clarity across all sub-topics in this chapter.

Additional Study Resources for Class 12 Computer Science

Explore our broader library of printable assignments, chapter notes, and mock tests designed to support continuous revision and secure higher marks in CBSE assessments.

FAQs

Where can I download the latest PDF for CBSE Class 12 Computer Science File Handling Worksheet Set 02?

You can download the teacher-verified PDF for CBSE Class 12 Computer Science File Handling Worksheet Set 02 from StudiesToday.com. These practice sheets for Class 12 Computer Science are designed as per the latest CBSE academic session.

Are these Computer Science Class 12 worksheets based on the 2026-27 competency-based pattern?

Yes, our CBSE Class 12 Computer Science File Handling Worksheet Set 02 includes a variety of questions like Case-based studies, Assertion-Reasoning, and MCQs as per the 50% competency-based weightage in the latest curriculum for Class 12.

Do you provide solved answers for CBSE Class 12 Computer Science File Handling Worksheet Set 02?

Yes, we have provided detailed solutions for CBSE Class 12 Computer Science File Handling Worksheet Set 02 to help Class 12 and follow the official CBSE marking scheme.

How does solving CBSE Class 12 Computer Science File Handling Worksheet Set 02 help in exam preparation?

Daily practice with these Computer Science worksheets helps in identifying understanding gaps. It also improves question solving speed and ensures that Class 12 students get more marks in CBSE exams.

Is there any charge for the Class 12 Computer Science practice test papers?

All our Class 12 Computer Science practice test papers and worksheets are available for free download in mobile-friendly PDF format. You can access CBSE Class 12 Computer Science File Handling Worksheet Set 02 without any registration.