pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/TheAlgorithms/Python/commit/c1dc8e97f7992c132c671da2da60da9d926d0fca

.css" /> Create count_vowels.py (#11474) · TheAlgorithms/Python@c1dc8e9 · GitHub
Skip to content

Commit c1dc8e9

Browse files
Create count_vowels.py (#11474)
* Create count_vowels.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 716bdeb commit c1dc8e9

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

strings/count_vowels.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
3
13+
>>> count_vowels("123 hello world")
14+
3
15+
>>> count_vowels("")
16+
0
17+
>>> count_vowels("a quick brown fox")
18+
5
19+
>>> count_vowels("the quick BROWN fox")
20+
5
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+
34+
testmod()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy