कथन 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:
-
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
. - The module needed for pickling (saving data to a file) in Python is
-
f = open("stud.dat", "____________")
(Statement 2):- This line is opening a file
stud.dat
in write mode. Since we're usingpickle
to save the data, the correct mode would be"wb"
(write binary mode). - So, the correct fill for this statement would be
"wb"
.
- This line is opening a file
-
__________ .dump(rec, f)
(Statement 3):- The correct method to save data to a file using
pickle
ispickle.dump()
. - So,
pickle.dump(rec, f)
would serialize and save therec
list to the filef
.
- The correct method to save data to a file using
-
_______.close()
(Statement 4):- This closes the file
f
, sof.close()
is used here.
- This closes the file
Conclusion:
For Statement 3, the correct answer is pickle.dump()
.
Answer:
(B) pickle