CBSE · 083Class XII · 2025Section E2 marks
Question 36ii
4 March 2025 · Computer Science (083)
(ii) SearchDestn(D) - to read contents from the file PASSENGERS.DAT and display the details of those Passengers whose DESTN matches with the value of D.
Answer
python
def SearchDestn(D):
F=open("PASSENGERS.DAT", "rb")
try:
while True:
Rec=pickle.load(F)
if Rec[3]==D:
print(Rec)
except EOFError:
F.close()Explanation
Reads binary file record by record until EOF, checking index 3 for destination.