We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 716bdeb commit 913efdcCopy full SHA for 913efdc
strings/count_vowels.py
@@ -0,0 +1,33 @@
1
+def count_vowels(s: str) -> int:
2
+ """
3
+ Count the number of vowels in a given string.
4
+
5
+ :param s: Input string to count vowels in.
6
+ :return: Number of vowels in the input string.
7
8
+ Examples:
9
+ >>> count_vowels("hello world")
10
+ 3
11
+ >>> count_vowels("HELLO WORLD")
12
13
+ >>> count_vowels("123 hello world")
14
15
+ >>> count_vowels("")
16
+ 0
17
+ >>> count_vowels("a quick brown fox")
18
+ 5
19
+ >>> count_vowels("the quick BROWN fox")
20
21
+ >>> count_vowels("PYTHON")
22
+ 1
23
24
+ if not isinstance(s, str):
25
+ raise ValueError("Input must be a string")
26
27
+ vowels = "aeiouAEIOU"
28
+ return sum(1 for char in s if char in vowels)
29
30
31
+if __name__ == "__main__":
32
+ from doctest import testmod
33
+ testmod()
0 commit comments