-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvowels.py
65 lines (39 loc) · 1.09 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def has_vowel(s):
"""(str) -> bool
Return True if and only if s has at least one vowel, not including y.
>>> has_vowel("Anniversary")
True
>>> has_vowel("xyz")
False
"""
vowel_found = False
for char in s:
if char in 'aeiouAEIOU':
vowel_found = True
return vowel_found
def collect_vowels (s):
'''(str) -> str
Return the vowels from s. Do not treat
y as a vowel.
>>>collect_vowels ('Happy Anniversary!')
'aAiea'
>>>collect_vowels ('xyz')
'''
vowels = ''
for char in s:
if char in 'aeiuoAEIUO':
vowels = vowels + char
return vowels
def count_vowels (s):
'''(str)-> int
rturn the vowels in s.Do not treat y as a vowel.
>>>count_vowels('Happy aniversary!')
5
>>>count_vowels ('xyz')
0
'''
num_vowels = 0
for char in s:
if char in 'aeiuoAEIUO':
num_vowels = num_vowels + 1
return num_vowels