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

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

Choose the answer for statement 3.

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:

Let's break down the code and identify the correct answer for Statement 3:

Given code structure:

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

Explanation:

  1. import ___________ (Statement 1):

    • The module needed for pickling (saving data to a file) in Python is pickle.

    So, the correct module to import is pickle.

  2. f = open("stud.dat", "____________") (Statement 2):

    • This line is opening a file stud.dat in write mode. Since we're using pickle to save the data, the correct mode would be "wb" (write binary mode).
    • So, the correct fill for this statement would be "wb".
  3. __________ .dump(rec, f) (Statement 3):

    • The correct method to save data to a file using pickle is pickle.dump().
    • So, pickle.dump(rec, f) would serialize and save the rec list to the file f.
  4. _______.close() (Statement 4):

    • This closes the file f, so f.close() is used here.

Conclusion:

For Statement 3, the correct answer is pickle.dump().

Answer:

(B) pickle

Latest Updates