Question:medium

Write a Python function that displays all the words starting and ending with a vowel from a text file "Report.txt".
The consecutive words should be separated by a space in the output.
For example, if the file contains:
Once there was a wise man in a village.
He was an awesome story-teller.
He was able to keep people anchored while listening to him.
Then the output should be:
Once a a awesome able

Show Hint

Always strip punctuation before checking characters.
This avoids false results due to trailing symbols like . or ,.
Updated On: Jan 14, 2026
Show Solution

Solution and Explanation

The following Python function processes text:
def display_vowel_words():
    vowels = "AEIOUaeiou"
    result = []
    with open("Report.txt", "r") as f:
        for line in f:
            words = line.split()
            for word in words:
                clean_word = word.strip(".,?!")
                if clean_word and clean_word[0] in vowels and clean_word[-1] in vowels:
                    result.append(clean_word)
    print(" ".join(result))
This function initializes a vowels string. It reads the file "Report.txt" line by line. Each line is segmented into words using split(). Punctuation is removed from each word via strip(".,?!"). The function then verifies if a word commences and concludes with a vowel. Qualifying words are collected in the result list. Lastly, the collected words are concatenated with spaces and displayed.
Was this answer helpful?
1