Completed

Class 12 CS – Binary File Handling Moderate Level

Class 12 · Computer Science Sun, 20 Sep 2026 10:00 PM 60s / question 15 questions · 15 marks

Questions From This Challenge

Q1mcq1 mark
Which combination is most appropriate for reading an existing binary file without modifying its contents?
open("data.dat", "wb")
open("data.dat", "rb") ✓
open("data.dat", "ab")
open("data.dat", "wb+")
Q2mcq1 mark
What is the purpose of pickle.dump() when working with a binary file?
To retrieve an object from a binary file
To convert a binary file into a text file
To write a Python object into a binary file ✓
To delete an object from a binary file
Q3mcq1 mark
What happens when the following statement is executed on an existing binary file? f = open("data.dat", "wb")
Existing contents are preserved and new data is appended
Existing contents are deleted and the file is opened for writing ✓
The file is opened only for reading
The file is opened only if it already exists
Q4mcq1 mark
Consider the following code: import pickle f = open("data.dat", "wb") pickle.dump(10, f) pickle.dump(20, f) f.close() Later, the file is opened using "rb". How many separate objects can be retrieved using two successive pickle.load() calls?
1
2 ✓
10
30
Q5mcq1 mark
Which mode is suitable when new binary records need to be added to the end of an existing binary file without deleting its existing contents?
rb
wb
ab ✓
rb+
Q6mcq1 mark
What exception is normally encountered when pickle.load() attempts to read beyond the available stored objects in a binary file?
ValueError
TypeError
EOFError ✓
IndexError
Q7mcq1 mark
A binary file contains records in the form: [101, "Amit", 85] [102, "Riya", 92] [103, "Karan", 78] Which approach is appropriate to search for the record whose roll number is 102?
Read each record using pickle.load() and compare record[0] with 102 ✓
Use record.find(102)
Use pickle.dump(102, f) while reading
Use readlines() and compare each line
Q8mcq1 mark
Consider the following code: import pickle f = open("data.dat", "wb") pickle.dump(25, f) pickle.dump(50, f) f.close() f = open("data.dat", "rb") x = pickle.load(f) y = pickle.load(f) print(x + y) What will be printed?
25
50
75 ✓
125
Q9mcq1 mark
A binary file contains student records. To update the marks of the student whose roll number is 105, which operation is generally required?
Read the required record, modify it, and rewrite the updated records into a binary file ✓
Use pickle.load() directly to change the stored record
Use pickle.dump() without opening the file
Use append mode to overwrite the existing record at its original position
Q10mcq1 mark
Which statement correctly distinguishes rb and rb+?
rb allows reading only, while rb+ allows both reading and writing ✓
rb allows writing only, while rb+ allows reading only
Both modes allow only reading
Both modes delete the existing contents before reading
Q11output1 mark
What will be the output?
import pickle

f = open("data.dat", "wb")
pickle.dump(15, f)
pickle.dump(25, f)
f.close()

f = open("data.dat", "rb")
a = pickle.load(f)
b = pickle.load(f)
print(b - a)
Correct output: 10
Q12output1 mark
What will be the output?
import pickle

f = open("data.dat", "wb")
pickle.dump(10, f)
pickle.dump(20, f)
pickle.dump(30, f)
f.close()

f = open("data.dat", "rb")
pickle.load(f)
x = pickle.load(f)
print(x)
Correct output: 20
Q13output1 mark
What will be the output?
import pickle

f = open("data.dat", "wb")
pickle.dump([10, 20], f)
f.close()

f = open("data.dat", "rb")
x = pickle.load(f)
x.append(30)
print(x)
Correct output: [10, 20, 30]
Q14output1 mark
What will be the output?
import pickle

f = open("data.dat", "wb")
pickle.dump(5, f)
pickle.dump(10, f)
f.close()

f = open("data.dat", "rb")
a = pickle.load(f)
b = pickle.load(f)
print(a * b)
Correct output: 50
Q15output1 mark
What will be the output?
import pickle

f = open("data.dat", "wb")
pickle.dump(10, f)
pickle.dump(20, f)
pickle.dump(30, f)
f.close()

f = open("data.dat", "rb")
a = pickle.load(f)
pickle.load(f)
c = pickle.load(f)
print(a + c)
Correct output: 40
Next Live Challenge
Mixed: DML + Retrieval - Combined Application
Class 12 · Computer Science Fri, 23 Oct 2026, 9:00 PM
View Live Challenges →

← Back to Live Challenge History · Practice MCQs

CodeBuddy
Hi there! 👋 I'm CodeBuddy, your KV Coders assistant.

To help me give you the most accurate answers, please select your class and subject below, or just type your question!
Buddy is typing...