- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy pathcount_vowels.py
34 lines (28 loc) · 744 Bytes
/
count_vowels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
defcount_vowels(s: str) ->int:
"""
Count the number of vowels in a given string.
:param s: Input string to count vowels in.
:return: Number of vowels in the input string.
Examples:
>>> count_vowels("hello world")
3
>>> count_vowels("HELLO WORLD")
3
>>> count_vowels("123 hello world")
3
>>> count_vowels("")
0
>>> count_vowels("a quick brown fox")
5
>>> count_vowels("the quick BROWN fox")
5
>>> count_vowels("PYTHON")
1
"""
ifnotisinstance(s, str):
raiseValueError("Input must be a string")
vowels="aeiouAEIOU"
returnsum(1forcharinsifcharinvowels)
if__name__=="__main__":
fromdoctestimporttestmod
testmod()