From 913efdc20affd7c3d036d0133ae29016db57de59 Mon Sep 17 00:00:00 2001 From: Saurabh Mahapatra <98408932+its-100rabh@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:59:42 +0530 Subject: [PATCH 1/2] Create count_vowels.py --- strings/count_vowels.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 strings/count_vowels.py diff --git a/strings/count_vowels.py b/strings/count_vowels.py new file mode 100644 index 000000000000..d579ff143af0 --- /dev/null +++ b/strings/count_vowels.py @@ -0,0 +1,33 @@ +def count_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 + """ + if not isinstance(s, str): + raise ValueError("Input must be a string") + + vowels = "aeiouAEIOU" + return sum(1 for char in s if char in vowels) + + +if __name__ == "__main__": + from doctest import testmod + testmod() From eba698e0362e81a39c4cc7efe76a8249daf1b905 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:32:31 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/count_vowels.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/strings/count_vowels.py b/strings/count_vowels.py index d579ff143af0..8a52b331c81b 100644 --- a/strings/count_vowels.py +++ b/strings/count_vowels.py @@ -4,7 +4,7 @@ def count_vowels(s: str) -> int: :param s: Input string to count vowels in. :return: Number of vowels in the input string. - + Examples: >>> count_vowels("hello world") 3 @@ -30,4 +30,5 @@ def count_vowels(s: str) -> int: if __name__ == "__main__": from doctest import testmod + testmod()