Completed

Mixed: Text + Binary + CSV revision

Class 12 · Computer Science Mon, 12 Oct 2026 9:00 PM 60s / question 15 questions · 15 marks

Questions From This Challenge

Q1mcq1 mark
Which module would you use to store a Python dictionary object directly to a file without first converting it to text?
csv
pickle ✓
os
sys
Q2mcq1 mark
Which of these file types is typically opened in text mode for direct reading with open(filename, "r")?
.dat file created by pickle
.csv file ✓
.jpg image
compiled .pyc file
Q3mcq1 mark
To store tabular data (rows and columns), such as student marks, so that it can later be opened in a spreadsheet program, which file type is most appropriate?
A binary file using pickle
A CSV file ✓
A plain .txt file with no defined structure
A compiled binary executable
Q4mcq1 mark
Which pair correctly matches a file type to its typical open mode for writing?
Binary file with pickle -> "wb"; CSV file -> "w" (with newline="") ✓
Binary file with pickle -> "w"; CSV file -> "wb"
Both always use "rb"
Both always use "a"
Q5mcq1 mark
What is the key difference in purpose between the csv module and the pickle module?
csv is for storing structured row/column data as text; pickle is for serializing arbitrary Python objects as byte streams ✓
They are functionally identical and interchangeable
csv only works with numbers; pickle only works with text
pickle is only meant for storing images
Q6mcq1 mark
Which of the following correctly closes a file automatically after the block finishes, regardless of whether it is a text, binary, or CSV file?
Using the `with` clause when opening the file ✓
Only calling open() without close()
Setting the mode to "auto"
Files close automatically only for CSV files
Q7output1 mark
What is the output?
with open("m1.txt", "w") as f:
    f.write("Revision Day")

with open("m1.txt", "r") as f:
    print(f.read())
Correct output: Revision Day
Q8output1 mark
What is the output?
import pickle
record = ("Maya", 15, "XII-A")
with open("m2.dat", "wb") as f:
    pickle.dump(record, f)

with open("m2.dat", "rb") as f:
    print(pickle.load(f))
Correct output: ('Maya', 15, 'XII-A')
Q9output1 mark
What is the output?
import csv
with open("m3.csv", "w", newline="") as f:
    writer = csv.writer(f)
    writer.writerows([["Subject", "Grade"], ["Physics", "A"], ["Maths", "A+"]])

with open("m3.csv", "r", newline="") as f:
    reader = csv.reader(f)
    rows = list(reader)
print(len(rows))
Correct output: 3
Q10output1 mark
What is the output?
with open("m4.txt", "w") as f:
    f.write("Start-")

with open("m4.txt", "a") as f:
    f.write("End")

with open("m4.txt", "r") as f:
    f.seek(0)
    print(f.read())
Correct output: Start-End
Q11output1 mark
What is the output?
import csv

def saveStudent(filename, name, marks):
    with open(filename, "a", newline="") as f:
        writer = csv.writer(f)
        writer.writerow([name, marks])

with open("m5.csv", "w", newline="") as f:
    writer = csv.writer(f)
    writer.writerow(["Name", "Marks"])

saveStudent("m5.csv", "Dev", 81)
saveStudent("m5.csv", "Isha", 94)

with open("m5.csv", "r", newline="") as f:
    reader = csv.reader(f)
    for row in reader:
        print(row)
Correct output: ['Name', 'Marks'] ['Dev', '81'] ['Isha', '94']
Q12output1 mark
What is the output?
import pickle
with open("m6.dat", "wb") as f:
    pickle.dump([1, 2, 3], f)

with open("m6.dat", "rb") as f:
    data = pickle.load(f)
    try:
        more = pickle.load(f)
        print(more)
    except EOFError:
        print("End of pickle data")
print(data)
Correct output: End of pickle data [1, 2, 3]
Q13output1 mark
What is the output?
with open("m7.txt", "w") as f:
    f.writelines(["Mon\n", "Tue\n", "Wed\n"])

with open("m7.txt", "r") as f:
    lines = f.readlines()
print(len(lines))
Correct output: 3
Q14output1 mark
What is the output?
import csv
try:
    with open("m8.csv", "r", newline="") as f:
        reader = csv.reader(f)
        rows = list(reader)
except FileNotFoundError:
    print("Not found")
else:
    print("Found")
finally:
    print("Done checking")
Correct output: Not found Done checking
Q15output1 mark
What is the output?
import pickle

def wordCount(text):
    words = text.split()
    return len(words)

sentence = "Computer Science is fun"
with open("m9.txt", "w") as f:
    f.write(sentence)
with open("m9.dat", "wb") as f:
    pickle.dump(wordCount(sentence), f)

with open("m9.dat", "rb") as f:
    print(pickle.load(f))
Correct output: 4
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...