The function that counts the number of times a vowel exist in a string is as follows:
def count_vowels(string, dictionary):
vowels = 'aeiou'
dictionary = {}.fromkeys(vowels, 0)
for i in string:
if i in vowels:
dictionary[i] += 1
return dictionary
print(count_vowels("trouble", {}))
Code explanation.
The code is written in python.
- we defined a function named "count_vowels". The function accept a string and an empty dictionary.
- Then. we store the vowels in a variable vowels.
- The dictionary is used to store the key value pair i.e the vowels and the number of times they appear.
- We looped through the string.
- If any value in the string is in vowels, we increase the dictionary values by 1.
- Then, we return the dictionary.
- Finally, we call the function with it parameters.
learn more on function here: https://brainly.com/question/27219031