Completed
Class 12 CS – Binary File Handling Live Challenge
Questions From This Challenge
Q1mcq1 mark
Which module is used in Python to store and retrieve Python objects in a binary file?
csv
pickle ✓
binary
object
Q2mcq1 mark
Which mode opens an existing binary file for reading without modifying its contents?
"r"
"rb" ✓
"br"
"wb"
Q3mcq1 mark
A binary file needs to be opened so that new data can be added at the end while preserving its existing contents. Which mode is appropriate?
"rb"
"wb"
"ab" ✓
"rb+"
Q4mcq1 mark
What is the main difference between pickle.dump() and pickle.load()?
dump() retrieves an object and load() stores an object
dump() stores an object and load() retrieves an object ✓
Both functions only store objects
Both functions only retrieve objects
Q5mcq1 mark
A binary file contains three Python objects stored using pickle.dump(). If pickle.load() is called twice consecutively on the file, what happens?
The first object is returned both times
The first two stored objects are returned ✓
All three objects are returned automatically
The entire file is returned as one object
Q6output1 mark
What will be the output of the following Python code?
import pickle
with open("data.dat", "wb") as f:
pickle.dump(10, f)
pickle.dump(20, f)
with open("data.dat", "rb") as f:
a = pickle.load(f)
b = pickle.load(f)
print(a * b)
Correct output:
200Q7output1 mark
What will be the output of the following Python code?
import pickle
with open("data.dat", "wb") as f:
pickle.dump("A", f)
pickle.dump("B", f)
pickle.dump("C", f)
with open("data.dat", "rb") as f:
pickle.load(f)
x = pickle.load(f)
print(x)
Correct output:
BQ8output1 mark
What will be the output of the following Python code?
import pickle
with open("data.dat", "wb") as f:
pickle.dump(100, f)
pickle.dump(200, f)
with open("data.dat", "rb") as f:
print(pickle.load(f))
print(f.tell())
Correct output:
100
5Q9mcq1 mark
A binary file contains records stored using pickle. A program needs to examine each record until no more records are available. Which exception is normally handled to detect the end of the file while repeatedly using pickle.load()?
ValueError
TypeError
EOFError ✓
NameError
Q10output1 mark
What will be the output of the following Python code?
import pickle
with open("data.dat", "wb") as f:
pickle.dump(15, f)
pickle.dump(25, f)
pickle.dump(35, f)
with open("data.dat", "rb") as f:
a = pickle.load(f)
f.seek(0)
b = pickle.load(f)
print(a, b)
Correct output:
15 15Q11mcq1 mark
A binary file contains student records stored as Python objects. Which operation is most appropriate when a program needs to find a particular student's record based on a stored roll number?
Read each stored record and compare its roll number ✓
Use csv.reader() to search the binary file
Use writerow() to search the records
Use append mode to locate the record
Q12mcq1 mark
A program opens a binary file using "wb" and writes a new record. What happens to the existing contents of the file?
They remain unchanged
They are moved to the end of the file
They are overwritten because the file is opened in write mode ✓
They are automatically converted into text
Q13output1 mark
What will be the output of the following Python code?
import pickle
with open("data.dat", "wb") as f:
pickle.dump([10, 20], f)
with open("data.dat", "rb") as f:
data = pickle.load(f)
data.append(30)
print(data)
Correct output:
[10, 20, 30]Q14mcq1 mark
A binary file contains several student records. A program reads a record, changes one value in that record, and needs to save the modified record back to the file. Which general operation is required for updating the stored record?
Read the record, modify it, and write the updated record back ✓
Only open the file in "rb" mode and read the record
Open the file in "ab" mode and ignore the existing record
Use csv.writer() to replace the record
Q15output1 mark
What will be the output of the following Python code?
import pickle
with open("data.dat", "wb") as f:
pickle.dump(5, f)
pickle.dump(10, f)
pickle.dump(15, f)
with open("data.dat", "rb") as f:
total = 0
try:
while True:
total += pickle.load(f)
except EOFError:
pass
print(total)
Correct output:
30