easy +10 pts

Count Syllables (Simple)

Write a function that counts the number of syllables in a given word by treating each group of adjacent vowels as one syllable.

Define a function `count_syllables(word: str) -> int` that returns the number of syllables in a word. A syllable is defined as a contiguous group of vowels (a, e, i, o, u, both lowercase and uppercase). For example, the word "code" has two vowel groups ('o' and 'e'), so it has 2 syllables. The word "queue" has one group ("ueue"), so it has 1 syllable. The word "beautiful" has three groups ("eau", "i", "u"), so it has 3 syllables. Words with no vowels have 0 syllables. The input will be a non-empty string containing only alphabetic characters (letters).

Constraints

- `1 <= len(word) <= 1000` - `word` consists of ASCII letters only, both uppercase and lowercase. - Time complexity should be O(n) where n is the length of the word.

Example

```python
>>> count_syllables("hello")
2
>>> count_syllables("code")
2
>>> count_syllables("queue")
1
>>> count_syllables("beautiful")
3
>>> count_syllables("why")
0
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Iterate through the string and keep track of whether the previous character was a vowel.
When you see a vowel that is not preceded by a vowel, increment your counter.
Remember to treat both uppercase and lowercase vowels the same.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.