Skip to content
Question 19 of 22

Q.(a) 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 1969, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about 400 km, serves as a hub for research. With missions planned for 2030, humanity’s cosmic journey continues! Then the function should return 11.

(OR)
(b) 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 1969, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about 400 km, serves as a hub for research. With missions planned for 2030, humanity’s cosmic journey continues! Then the function should display : incredible advancements science. agencies serves research.
Yanam CbseCBSE Class XII Board 2026Subjective· 3mImportance★★★★★
86% · 19/22 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a) reads the file and counts every digit character with isdigit() (returns 11 here); Part (b) splits the file into words and prints those containing the lowercase letter e at least twice.

Part (a)

We must count how many digit characters (0–9) occur in Space.txt.

Approach

  1. Open the file in read mode and read the entire content into a string.
  2. Walk over every character; str.isdigit() is True only for '0'–'9'.
  3. Keep a running counter and return it.
def countDigits():
    count = 0
    with open("Space.txt", "r") as f:
        for ch in f.read():
            if ch.isdigit():
                count += 1
    return count

print(countDigits())
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.