In: Computer Science
This task is solved in Python 3.
Develop a function which counts the number of vowels in a text.
>>> numberofVowels ("There is a cat outside the house")
13
Hello learner,
Thanks for asking.
Here is the required code in python.
def countVowels(sentence):
count = 0
# convert the each letter of sentence in lower
sentence = sentence.lower()
# use for loop to count the vowel
for i in sentence:
if i in ['a', 'e', 'i', 'o', 'u']:
count += 1
return count
if __name__ == '__main__':
n = str(input("Enter the string to check for vowels: "))
count = countVowels(n)
print(count)
Here is the required code with proper output.
Use proper indentation(space) for less error in the code.
In this code at first sentence is converted into lower digits and then one by one vowel is counted from the string after that number of vowel is printed on the screen.
please upvote and ask if you have any query.