CBSE 2026 · Central · Set 4 · Q29 · 3 marks
Write a Python function that counts and returns the number of digits appearing in the text file "Space.txt". For example, if the file contains : Space exploration has unlocked incredible advancements in technology and science. Since the first moon landing in $\displaystyle 1969$, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about $\displaystyle 400$ km, serves as a hub for research. With missions planned for $\displaystyle 2030$, humanity's cosmic journey continues! Then the function should return 11.Write a Python function that displays the words in which the lowercase letter 'e' appears at least twice in the text file 'Space.txt'. For example, if the file contains: Space exploration has unlocked incredible advancements in technology and science. Since the first moon landing in $\displaystyle 1969$, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about $\displaystyle 400$ km, serves as a hub for research. With missions planned for $\displaystyle 2030$, humanity's cosmic journey continues! Then the function should display :incredible advancements science. agencies serves research.
Write a Python function that counts and returns the number of digits appearing in the text file "Space.txt". For example, if the file contains : Space exploration has unlocked incredible advancements in technology and science. Since the first moon landing in $\displaystyle 1969$, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about $\displaystyle 400$ km, serves as a hub for research. With missions planned for $\displaystyle 2030$, humanity's cosmic journey continues! Then the function should return 11.
Write a Python function that displays the words in which the lowercase letter 'e' appears at least twice in the text file 'Space.txt'. For example, if the file contains: Space exploration has unlocked incredible advancements in technology and science. Since the first moon landing in $\displaystyle 1969$, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about $\displaystyle 400$ km, serves as a hub for research. With missions planned for $\displaystyle 2030$, humanity's cosmic journey continues! Then the function should display :
incredible advancements science. agencies serves research.
Marking-scheme solution
(a)
def CountDigits():
with open("Space.txt",'r') as F:
Data=F.read()
C=0
for CH in Data:
if CH.isdigit(): # OR if CH in '0123456789'
C+=1 # OR if CH >= '0' and CH <= '9'
return C
def CountDigits():
F = open("Space.txt")
All=F.readlines()
C=0
for Line in All:
for CH in Line:
if CH.isdigit(): # OR if CH in '0123456789'
C+=1 # OR if CH >= '0' and CH <= '9'
F.close()(b)
def showWords():
with open("Space.txt",'r') as F:
All=F.read()
Words=All.split()
for word in Words:
if word.count('e')>=2:
print(word, end=' ')
OR
def showWords():
F = open("Space.txt") #'r'/ 'rt' is optional
All=F.readlines()
for L in All:
Words=L.split()
for Word in Words :
C=Word.count('e')
if C>=2:
print(Word, end= ' ')
F.close()OR Any other equivalent correct code
File Handling - Text FilesReading using read(), readline() and readlines()Applyshort_answer
CBSE Class 12 Computer Science past-paper question from the 2026board exam, with the answer as CBSE’s own marking scheme gives it. Where our answers come from.