Find the output of the following Python Code: Assume records.dat contains…

PYQ KVS TGT/PGT 2026

Find the output of the following Python Code:
Assume records.dat contains three pickled integers: 10, 20 and 30.

import pickle
def UpdateBinary():
    # Read all into a list
    Data = []
    with open("records.dat", "rb") as F:
        try:
            while True:
                Data.append(pickle.load(F))
        except EOFError:
            pass
    # Update logic
    Data[1] = Data[1] * 5
    with open("records.dat", "wb") as F:
        pickle.dump(Data[1], F)
    with open("records.dat", "rb") as F:
        FinalVal = pickle.load(F)
        f.seek(0, 2)
        Size = F.tell()
    print(Data[0])
    print(FinalVal)
    print(len(Data))
    print(Size > 0)
UpdateBinary()

Attempted by 24 students.

Sign up free to check your answer

Sign up free

Explore the full course: Kvs Nvs Tier 2 Computer Science

Loading lesson…