Authentic CBSE board questions & official stepwise marking scheme solutions for Text Files (Chapter 4A).
File Handling: Text Files PYQs (2022–2026)
Complete collection of text file manipulation questions: open(), access modes (r, w, a, r+), read(), readline(), readlines(), seek(), tell(), and character/word/line counting algorithms.
Key Topics: Access Modes (r, w, a, r+), read() vs readline() vs readlines(), seek() and tell() Methods, Word & Character Counting, Line-by-Line File Processing
Text Files Previous Year Questions & Solutions (9 Questions)
Q29 • CBSE 2026 • 3 Marks • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2026) 3-Mark Board Question Q29
Official CBSE Marking Scheme Solution
def count_digits():
with open("space.txt", "r") as f:
return sum(ch.isdigit() for ch in f.read())
def words_with_two_e():
with open("space.txt", "r") as f:
for word in f.read().split():
if word.count("e") >= 2:
print(word, end=" ")

Q29 • CBSE 2025 • 3 Marks • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2025) 3-Mark Board Question Q29
Official CBSE Marking Scheme Solution
def show_vote_lines():
with open("Elections.txt", "r") as f:
for line in f:
if "vote" in line:
print(line, end="")
def vowel_words():
vowels = "aeiouAEIOU"
with open("Report.txt", "r") as f:
for word in f.read().split():
if word[0] in vowels and word[-1] in vowels:
print(word, end=" ")

Q16 • CBSE 2024 • 1 Mark • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2024) 1-Mark Board Question Q16
Official CBSE Marking Scheme Solution
Option C — seek(0, -1) is invalid because the reference point must be 0, 1, or 2.

Q17 • CBSE 2024 • 1 Mark • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2024) 1-Mark Board Question Q17
Official CBSE Marking Scheme Solution
Both assertion and reason are true, but the reason does not explain the assertion.

Q28 • CBSE 2024 • 3 Marks • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2024) 3-Mark Board Question Q28
Official CBSE Marking Scheme Solution
import re
def showInlines():
with open("STORY.TXT", "r") as f:
text = f.read()
for sentence in re.split(r"(?<=[.!?])\s*", text.strip()):
if sentence: print(sentence)
def c_words():
upper = lower = 0
with open("Words.txt", "r") as f:
for ch in f.read():
if ch.isupper(): upper += 1
elif ch.islower(): lower += 1
print("Uppercase:", upper)
print("Lowercase:", lower)

Q34 • CBSE 2024 • 5 Marks • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2024) 5-Mark Board Question Q34
Official CBSE Marking Scheme Solution
w creates/truncates a file; a appends at the end. with closes the file automatically when the block exits.

Q6 • CBSE 2023 • 1 Mark • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2023) 1-Mark Board Question Q6
Official CBSE Marking Scheme Solution
Option D — a (append mode) positions writes at the end.

Q11 • CBSE 2023 • 1 Mark • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2023) 1-Mark Board Question Q11
Official CBSE Marking Scheme Solution
Option A — 0 is the default reference point for seek().

Q27 • CBSE 2023 • 3 Marks • Text Files (Chapter 4A)
CBSE Class 12 Text Files (Chapter 4A) (2023) 3-Mark Board Question Q27
Official CBSE Marking Scheme Solution
Print each line where len(line.split()) >= 10.
count = 0
with open("Details.txt", "r") as f:
for word in f.read().split():
if word[-1].isdigit(): count += 1
print("Number of words ending with a digit are", count)
