Tuesday, May 14, 2019

codingdirectional: Count the vowel characters within a string with Python function

Hello and welcome back, we will start a new python project soon but for now, let us continue solving some python related problems first in this post and beyond.

The problem we are going to solve in this article goes like this: Given a string consists of lower case characters and spaces, you need to write a function to count the total vowel characters within that string. The solution is as follow.

def getCount(inputStr):
    num_vowels = 0
    li= list(inputStr)
    vovel= ['a','e','i','o','u']
    for i in li:
        if i in vovel:
            num_vowels+=1
        
    return num_vowels

The above function will only count the vowel character within a string and skips the other characters.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...