Write a Python function that takes a string as input and counts and returns the number of vowels in the string. Consider ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ as vowels.
Example 1:
Input: "hello world"
Output: 3
Example 2:
Input: "sky"
Output: 0
Use a loop to iterate through the characters in the string.
def count_vowels(s):
return sum(1 for char in s if char.lower() in 'aeiou')
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.