Completed

File Handling Intro + Text Files

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

Questions From This Challenge

Q1mcq1 mark
Which of the following is an example of a binary file?
A .txt file
A .csv file
A .jpg image file ✓
A .py source file
Q2mcq1 mark
Which statement about text files and binary files is correct?
Text files store data as characters (ASCII/Unicode); binary files store data as raw bytes not directly readable as text ✓
Binary files can only store integers
Text files cannot be opened using a text editor
Binary files always have the extension .txt
Q3mcq1 mark
Consider the path "C:\\Students\\Data\\marks.txt". This is an example of a/an:
Relative path
Absolute path ✓
Network path
Environment variable
Q4mcq1 mark
If "report.txt" is present in the same folder as the running Python script, which of these correctly opens it using a relative path?
open("report.txt") ✓
open("C:\\Users\\All\\report.txt") is the only valid option
A relative path cannot be used for files in the same folder
open() requires an absolute path always
Q5mcq1 mark
Which mode opens a text file for both reading and writing, but truncates (erases) all existing content of the file if it exists?
r+
w+ ✓
a+
r
Q6mcq1 mark
What happens if you try to open a file in "r" mode that does not exist on disk?
Python silently creates the file
A FileNotFoundError is raised ✓
The program continues with an empty file object
It automatically switches to write mode
Q7mcq1 mark
What is the main advantage of using the `with` clause while working with files in Python?
It automatically closes the file even if an exception occurs inside the block ✓
It makes the file permanently read-only
It converts binary files into text files
It increases the maximum file size Python can open
Q8mcq1 mark
Which mode should be used to open a file only for appending new text at the end, without erasing existing content, creating the file if it doesn't already exist?
w
a ✓
r+
r
Q9output1 mark
What is the output?
with open("data1.txt", "w") as f:
    f.write("CBSE Class 12")

with open("data1.txt", "r") as f:
    content = f.read()
print(content)
Correct output: CBSE Class 12
Q10output1 mark
What is the output?
with open("data2.txt", "w") as f:
    f.write("First Line")

with open("data2.txt", "w") as f:
    f.write("Second Line")

with open("data2.txt", "r") as f:
    print(f.read())
Correct output: Second Line
Q11output1 mark
What is the output?
with open("data3.txt", "w") as f:
    f.write("Hello")

with open("data3.txt", "a") as f:
    f.write(" World")

with open("data3.txt", "r") as f:
    print(f.read())
Correct output: Hello World
Q12output1 mark
What is the output?
try:
    f = open("nofile123.txt", "r")
    print(f.read())
except FileNotFoundError:
    print("File not found")
Correct output: File not found
Q13output1 mark
What is the output?
with open("data5.txt", "w") as f:
    f.write("Test")
print(f.closed)
Correct output: True
Q14output1 mark
What is the output?
with open("data6.txt", "w") as f:
    f.write("ABCDEF")

with open("data6.txt", "r+") as f:
    f.write("XYZ")

with open("data6.txt", "r") as f:
    print(f.read())
Correct output: XYZDEF
Q15output1 mark
What is the output?
with open("data7.txt", "a") as f:
    pass

with open("data7.txt", "r") as f:
    content = f.read()
print(len(content))
Correct output: 0
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...