globa print(x, y) ve function named double vowels (s) that takes a string s and
ID: 662656 • Letter: G
Question
globa print(x, y) ve function named double vowels (s) that takes a string s and returns a string in which all of the vowels (a, e, i, o, u) in s are "doubled" (i.e. replaced by two occurrences of themselves), and all non-vowels are left alone. For example: . double_vowels('about') should return the string 'aaboouut' double_vowels('time') should return the string 'tiimee You may assume that the input contains only lowercase letters. def double-vowels () doesn werk as a bose Case elf snot'n.aciou, : -1,S retum sto]2 rest etum return S rest = s : else SL0] in 'aciou. : else: retum SLo]t restExplanation / Answer
def double_vowels(s):
#Base Case
if s=='':
return ''
# If current first lettter is vowel double it
if s[0] in 'aieou':
newString= s[0]+s[0]+double_vowels(s[1:])
return newString
# If current first lettter is not a vowel keep it single
newString=s[0]+double_vowels(s[1:])
return newString
print double_vowels('about')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.