CBSE Class 12 Computer Science Question 33 of 44

Solved 2025 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 1

Back to all questions
1
Question

Question 29(a)

Write a Python function that displays all the words containing @cmail from a text file "Emails.txt".

Answer

Suppose the file "Emails.txt" contains the following text:

jagan@cmail.com 
aliya@gmail.com 
ali@cmail.net 
sara@cmail.edu 
mahi@yahoo.com.
def display_words():
    file = open("Emails.txt", 'r')
    content = file.read()
    words = content.split()            
    for word in words:
        if '@cmail' in word:
            print(word, end = ' ')
    file.close()
display_words()
Output
jagan@cmail.com ali@cmail.net sara@cmail.edu