CBSE 2026 · Central · Set 4 · Q36 · 5 marks
NextStep is an organization which has a pool of resource persons to conduct training workshops on various topics related to ICT. The data of all its Resource Persons is stored in a binary file RESOURCES.DAT using the following record structure (each record is a tuple) : (R_ID, R_Name, R_Expertise, Charges)
where:R_ID - Resource Person's ID (An integer) R_Name - Resource Person's Name (A string) R_Expertise - Area of expertise of the Resource Person Charges - Charges (in rupees) per hour to conduct a workshop For example, a record in the file is :(12, 'P. Velusami','Machine Learning',5000)
In this context, write the following user defined functions in Python :(i)Append() - To input the data of a Resource Person and write it in the file RESOURCES . DAT.(ii)Update() - To increase the Charges of each resource person by 500.
NextStep is an organization which has a pool of resource persons to conduct training workshops on various topics related to ICT. The data of all its Resource Persons is stored in a binary file RESOURCES.DAT using the following record structure (each record is a tuple) :
(R_ID, R_Name, R_Expertise, Charges)where:
R_ID - Resource Person's ID (An integer) R_Name - Resource Person's Name (A string) R_Expertise - Area of expertise of the Resource Person Charges - Charges (in rupees) per hour to conduct a workshop For example, a record in the file is :
(12, 'P. Velusami','Machine Learning',5000)In this context, write the following user defined functions in Python :
(i)
Append() - To input the data of a Resource Person and write it in the file RESOURCES . DAT.
(ii)
Update() - To increase the Charges of each resource person by 500.
Marking-scheme solution
(i)
import pickle
def Append(): #Assuming independent tuples in file
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:"))
Rec=(R_ID, R_Name, R_Expertise, Charges)
#[R_ID, R_Name, R_Expertise, Charges] also valid
pickle.dump (Rec, F)
F.close()
def Append(): #Assuming list of tuples in file
with open("RESOURCES.DAT","rb+") as F:
Rec=pickle.load(F)
R_ID = int(input("Resource Person ID:"))
R_Name = input("Resource Person Name:")
R_Expertise = input("Area of Expertise:")
Charges = int(input("Hourly Charges:"))
Rec.append((R_ID, R_Name, R_Expertise, Charges))
F.seek(0)
pickle.dump(Rec,F)
# Also consider a code, which reads from file using rb, and writes the
# appended content of records by reopening the same file in wb mode or
# dumping the content in a new file
(i)(ii)
Update() – To increase the Charges of each resource person by 500.
(ii) import pickle
def Update(): #Assuming independent tuples in file
F=open("RESOURCES.DAT","rb+")
try:
while True:
Pos=F.tell()
Rec=pickle.load(F)
Newrec=list(Rec)
Newrec[3]+=500
F.seek(Pos)
pickle.dump(tuple(Newrec),F)
except:
F.close()
import pickle #Assuming list of tuples in file
def Update():
with open("RESOURCES.DAT","rb+") as F:
Rec = pickle.load(F)
for I in range(len(Rec)):
Rec[I]=list(Rec[I])
Rec[I][3]+=500
F.seek(0)
pickle.dump(Rec,F)
# Also consider a code, which reads from file using rb, and writes the
# updated record by reopening the same file in wb mode or dumping the
# content in a new file
(ii)File Handling - Binary FilesSearch, Append and Update in a Binary FileApplylong_answer
More from File Handling - Binary Files
CBSE Class 12 Computer Science past-paper question from the 2026board exam, with the answer as CBSE’s own marking scheme gives it. Where our answers come from.