कथन 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:
- Statement 1 imports the necessary module, likely
pickle
because.dump()
is used. - Statement 2 opens the file
stud.dat
in write-binary mode (wb
), allowing us to write binary data to it. - Statement 3 uses
pickle.dump()
to serialize therec
list and save it to the filef
. - Statement 4 should close the file
f
after writing. To do this, you call.close()
on the file objectf
.
Thus, statement 4 should close the file object f
.
Answer:
(A) f