-
Notifications
You must be signed in to change notification settings - Fork 0
/
hasmorevowels.py
58 lines (37 loc) · 1.08 KB
/
hasmorevowels.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Does word contain more vowels than non-vowels?
If the word is over half vowels, it should return True:
>>> has_more_vowels("moose")
True
If it's half vowels (or less), it's false:
>>> has_more_vowels("mice")
False
>>> has_more_vowels("graph")
False
Don't consider "y" as a vowel:
>>> has_more_vowels("yay")
False
Uppercase vowels are still vowels:
>>> has_more_vowels("Aal")
True
"""
# store lowercase & uppercase in a set
# a string could work but a set has faster lookups
# create a counter for vowels
# loop though each letter in the word
# if letter = vowel, +1
# compare num of vowls > half of lenght of the word
def has_more_vowels(word):
"""Does word contain more vowels than non-vowels?"""
vowels = set('aioeuAIOEU')
counter = 0
for letter in word:
if letter in vowels:
counter += 1
if counter > len(word)/2:
return True
else:
return False
if __name__ == '__main__':
import doctest
if doctest.testmod().failed == 0:
print("\n*** ALL TESTS PASSED. HOORAY!\n")