CBSE · 083Class XII · 2025Section E1 mark

Question 36iii

4 March 2025 · Computer Science (083)

(iii) UpdateFare() - to increase the fare of all passengers by 5% and rewrite the updated records into the file PASSENGERS.DAT.

Answer

python
def UpdateFare():
    try:
        FR=open("PASSENGERS.DAT", "rb+")
        Rec=pickle.load(FR)
        for I in range(len(Rec)):
            Rec[I][4]+=(Rec[I][4] * 0.05) #OR Rec[I][4]=Rec[I][4] * 1.05)
        print("Updation Done!")
        FR.seek(0)
        pickle.dump(Rec, FR)
        FR.close()
    except:
        print("File not found!")

Explanation

Opens in read/write binary mode or uses temp file to update Fare field (index 4) by 5%.