KnowledgeBoat Logo

Computer Science

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

Python File Handling

2 Likes

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

Answered By

3 Likes


Related Questions