Question:

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.

Show Hint

Split the text into words and check w.count('e') for each word. Print the word if the count is 2 or more.
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Plan the function:
We need to look at every word of the file. For each word, we count how many times the lowercase letter 'e' appears. If the count is 2 or more, we display the word.
split() breaks the text into words at the spaces. The method count('e') gives the number of 'e' in a word.

Step 2: Write the function line by line:
def show_words():
    f = open('Space.txt', 'r')
    data = f.read()
    f.close()
    words = data.split()
    for w in words:
        if w.count('e') >= 2:
            print(w, end=' ')

The argument end=' ' keeps all the words on one line, separated by a space.

Step 3: Check with the sample text:
Words with two or more 'e': incredible (2), advancements (2), science. (2), agencies (2), serves (2), research. (2).
Words like Space, exploration and technology have only one 'e', so they are skipped. A capital E is not counted, because the rule is only for lowercase 'e'.
I ran the function on the sample text and it displayed: incredible advancements science. agencies serves research.

Final Answer:
The function show_words() above displays every word of Space.txt that has at least two lowercase 'e'.
Was this answer helpful?
0
0