Binary Files: Class 12 PYQs 2024–2026 with solutions
All 6 CBSE board questions asked from Binary Files in 3 board papers, with the year, set and marks of each. 6 are solved free below. The Class 12 Computer Science PYQ Book: Solved Board Papers 2024-2026 (CBSE) has every solution, all chapters and 3 full board papers.
Binary Files: board weightage
Board weightage 2024–2026
| Year | 2024 | 2025 | 2026 |
|---|---|---|---|
| Questions | 2 | 2 | 2 |
| Marks | 6 | 6 | 6 |
Most asked topics
6 questions from 3 papers. Repeated questions are shown once with every year they were asked.
1 mark: MCQ and Assertion–Reason
f1 = open("pqr.dat", "____"): correct mode to open in read only mode? (A) a (B) rb (C) r+ (D) rb+
Solution
(B) rb. .dat is a binary file; read-only binary mode is rb (r+ and rb+ also allow writing).
A–R. (A): For a binary file opened using 'rb' mode, pickle.dump() will display an error. (R): pickle.dump() is used to read from a binary file.
Solution
(C) A is true (an 'rb' file is read-only, so writing fails), but R is false: dump() writes; load() reads.
3 marks: short answer
(A)(ii) Binary file items.dat stores records as {item_id: [item_name, amount]}. Write Copy_new() that copies all records whose amount > 1000 to new_items.dat.
Solution
Assumption: the file holds one dictionary of all items.
import pickle
def Copy_new():
try:
with open("items.dat", "rb") as F1:
Data1 = pickle.load(F1)
Data2 = {}
for K, V in Data1.items():
if V[1] > 1000:
Data2[K] = V
with open("new_items.dat", "wb") as F2:
pickle.dump(Data2, F2)
except FileNotFoundError:
print("File not found!")
For {1:["Pen",500], 2:["Laptop",45000], 3:["Bag",1200]} the new file holds {2: ['Laptop', 45000], 3: ['Bag', 1200]}. (Part (i), 'w' vs 'a', is in Chapter 4.)
(B)(ii) EMP.DAT has records [Emp_Id, Name, Salary]. Write disp_Detail() to display employees whose salary is below 25000.
Solution
Assumption: each record dumped separately.
import pickle
def disp_Detail():
try:
with open("EMP.DAT", "rb") as F:
while True:
Data = pickle.load(F)
if Data[2] < 25000:
print(Data)
except EOFError:
pass
except FileNotFoundError:
print("File Not Found!!!")
5 marks: programs and case studies
RESOURCES.DAT stores tuples (R_ID, R_Name, R_Expertise, Charges), e.g. (12,'P. Velusami','Machine Learning',5000). Write (i) Append() to input a resource person's data and write it; (ii) Update() to increase the Charges of each person by 500. (2+3)
Solution
Assumption: each tuple dumped separately.
import pickle
def Append():
F = open("RESOURCES.DAT", "ab")
R_ID = int(input("Resource Person ID: "))
R_Name = input("Resource Person Name: ")
R_Expertise = input("Area of Expertise: ")
Charges = int(input("Hourly Charges: "))
pickle.dump((R_ID, R_Name, R_Expertise, Charges), F)
F.close()
def Update():
F = open("RESOURCES.DAT", "rb+")
try:
while True:
Pos = F.tell()
Rec = pickle.load(F)
Newrec = list(Rec) # tuples are immutable
Newrec[3] += 500
F.seek(Pos)
pickle.dump(tuple(Newrec), F)
except EOFError:
F.close()
(12, 'P. Velusami', 'Machine Learning', 5000) becomes (…, 5500). A tuple cannot be changed, so it is converted to a list, modified and converted back. Reading everything with 'rb' and rewriting with 'wb' is also accepted.
PASSENGERS.DAT stores [PNR, PName, BRDSTN, DESTN, FARE]. Write: (i) Create() to input data and write it; (ii) SearchDestn(D) to display passengers whose DESTN is D; (iii) UpdateFare() to increase all fares by 5% and rewrite the file.
Solution
Assumption: the file holds one list of all passenger records.
import pickle
def Create():
Rec = []
while True:
PNR = input("PNR No: ")
PName = input("Name: ")
BRDSTN = input("Boarding at: ")
DESTN = input("Destination: ")
FARE = float(input("Fare: "))
Rec.append([PNR, PName, BRDSTN, DESTN, FARE])
if input("More (Y/N)? ") in "Nn":
break
with open("PASSENGERS.DAT", "wb") as F:
pickle.dump(Rec, F)
def SearchDestn(D):
with open("PASSENGERS.DAT", "rb") as F:
Rec = pickle.load(F)
for R in Rec:
if R[3] == D:
print(R)
def UpdateFare():
with open("PASSENGERS.DAT", "rb") as F:
Rec = pickle.load(F)
for R in Rec:
R[4] = R[4] + R[4] * 0.05 # or R[4] *= 1.05
with open("PASSENGERS.DAT", "wb") as F:
pickle.dump(Rec, F)
print("Updation Done!")
Fares 1000.0 and 2000.0 become 1050.0 and 2100.0. Marks: (i) 1½ (ii) 1½ (iii) 2.
Get every solution for all chapters
- Every board question of every chapter, each fully solved the way the board gives marks
- 3 complete board papers, each followed by its solutions
- Weightage and most-asked topics for every chapter
- Instant PDF download, colour and black & white print copies
Revising the chapter first? Complete Computer Science Notes for Class 12 (CBSE 083, 2026-27) →
What you get in the pack
- CBSE Class 12 Computer Science board papers 2024 to 2026 (3 full board papers)
- All 14 chapters and 3 board papers complete
- Part A: all 14 chapters, questions sorted chapter-wise and by marks
- Year-wise weightage table and most-asked topics for every chapter
- Part B: each full board paper followed by its complete solutions
- Full programs; every output traced and verified by running the code
- Only the current syllabus in Part A
All chapters in this pack
- PYQ Ch 1 Python Revision Tour
- PYQ Ch 2 Functions
- PYQ Ch 3 Exception Handling
- PYQ Ch 4 Text Files
- PYQ Ch 5 Binary Files
- PYQ Ch 6 CSV Files
- PYQ Ch 7 Stack
- PYQ Ch 8 Computer Networks I: Evolution and Data Communication
- PYQ Ch 9 Computer Networks II: Devices, Topologies and Types
- PYQ Ch 10 Network Protocols and Web Services
- PYQ Ch 11 Database Concepts
- PYQ Ch 12 SQL: DDL, DML and Queries
- PYQ Ch 13 SQL: Aggregates, Grouping and Joins
- PYQ Ch 14 Interface of Python with MySQL
- Board Paper 2026 Set 91 with Solutions
- Board Paper 2025 Set 91 with Solutions
- Board Paper 2024 Set 91 with Solutions
