🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

कथन 4 के लिए उत्तर चुनें.

Choose the answer for statement 4.

import ___________ # statement 1
rec = [ ]
while True:
    rn = int(input("Enter"))
    nm = input("Enter")
    temp = [rn, nm]
    rec.append(temp)
    ch = input("Enter choice (Y/N)")
    if ch.upper == "N":
          break
f = open("stud.dat", "____________") #statement 2
__________ .dump(rec, f) #statement 3
_______.close( ) # statement 4
A)
B)
C)
D)

Explanation:

In this scenario, you're working with the pickle module to serialize data into a file. Let's look at statement 4 in the context of the code:

f = open("stud.dat", "____________")  # statement 2
__________ .dump(rec, f)  # statement 3
_______.close()  # statement 4

Explanation of the code:

  1. Statement 1 imports the necessary module, likely pickle because .dump() is used.
  2. Statement 2 opens the file stud.dat in write-binary mode (wb), allowing us to write binary data to it.
  3. Statement 3 uses pickle.dump() to serialize the rec list and save it to the file f.
  4. Statement 4 should close the file f after writing. To do this, you call .close() on the file object f.

Thus, statement 4 should close the file object f.

Answer:

(A) f

Latest Updates