-
Notifications
You must be signed in to change notification settings - Fork 244
Count Vowels
Andrew Burke edited this page Apr 11, 2024
·
1 revision
Unit 3 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Can the string include capital and lowercase characters?
- Yes, we will want to account for this.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Compare each character of the input string to vowels and sum the occurrences.
1) Set a string of vowels to compare to later
2) Set the count of vowels found to 0
3) Loop through the input string
a) If the lowercase version of the character is in the string of vowels, add one to the count
4) Return the count of vowels
def vowel_count(s):
vowels = "aeiou"
count = 0
for char in s:
if char.lower() in vowels:
count += 1
return count