CBSE Class 12 Computer Science Question 33 of 42

Solved 2024 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 4

Back to all questions
4
Question

Question 28(b)

Write a function, vowelCount() in Python that counts and displays the number of vowels in the text file named Poem.txt.

Answer

The Poem.txt file includes following data :

The sun sets in the west.
To be successful, one must work hard.
def vowelCount():
    fobj = open("Poem.txt", "r")
    data = str(fobj.read())
    cnt = 0
    for ch in data:
        if ch in "aeiouAEIOU":
            cnt = cnt + 1
    print(cnt)
    fobj.close()
vowelCount()
Output
16