Binary Files Class 12 PYQs 2024–2026 with Solutions | CBSE Computer Science Skip to content
Smart Notes for Every Exam · instant PDF download after payment +91 92520 37565
Class 12 · Computer Science · Chapter 5

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.

Cover of Class 12 Computer Science PYQ Book: Solved Board Papers 2024-2026 (CBSE)
Class 12 Computer Science PYQ book: every chapter + 3 board papers, all solved
₹99₹14934% off
Free sample

Binary Files: board weightage

Board weightage 2024–2026

Year202420252026
Questions222
Marks666

Most asked topics

Binary file programs6

6 questions from 3 papers. Repeated questions are shown once with every year they were asked.

Jump to: 1 mark3 marks5 marks

1 mark: MCQ and Assertion–Reason

Q1 · CBSE 2026 · 91 · Q101 mark

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).

Q2 · CBSE 2025 · 91 · Q201 mark

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

Q3 · CBSE 2024 · 91 · Q34(A)(ii)3 marks

(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.)

Q4 · CBSE 2024 · 91 · Q34(B)(ii)3 marks

(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

Q5 · CBSE 2026 · 91 · Q365 marks

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.

Q6 · CBSE 2025 · 91 · Q365 marks

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
See real pages (free sample)

Revising the chapter first? Complete Computer Science Notes for Class 12 (CBSE 083, 2026-27) →

What you get in the pack

All chapters in this pack

  1. PYQ Ch 1 Python Revision Tour
  2. PYQ Ch 2 Functions
  3. PYQ Ch 3 Exception Handling
  4. PYQ Ch 4 Text Files
  5. PYQ Ch 5 Binary Files
  6. PYQ Ch 6 CSV Files
  7. PYQ Ch 7 Stack
  8. PYQ Ch 8 Computer Networks I: Evolution and Data Communication
  9. PYQ Ch 9 Computer Networks II: Devices, Topologies and Types
  10. PYQ Ch 10 Network Protocols and Web Services
  11. PYQ Ch 11 Database Concepts
  12. PYQ Ch 12 SQL: DDL, DML and Queries
  13. PYQ Ch 13 SQL: Aggregates, Grouping and Joins
  14. PYQ Ch 14 Interface of Python with MySQL
  15. Board Paper 2026 Set 91 with Solutions
  16. Board Paper 2025 Set 91 with Solutions
  17. Board Paper 2024 Set 91 with Solutions
← PYQ Ch 4 Text Files PYQ Ch 6 CSV Files →

Prices shown in Indian rupees. Show prices in: ₹ INR · US$ USD