कथन 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
f
B
rec
C
file
D
stud
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
picklebecause.dump()is used. - Statement 2 opens the file
stud.datin write-binary mode (wb), allowing us to write binary data to it. - Statement 3 uses
pickle.dump()to serialize thereclist and save it to the filef. - Statement 4 should close the file
fafter writing. To do this, you call.close()on the file objectf.
Thus, statement 4 should close the file object f.
Answer:
(A) f
Correct Answer: A) f