我试图把一个字符串作为输入,并返回相同的字符串,每个元音乘以4并加上一个“!”最后添加。防爆。 '你好'返回,'heeeelloooo!'将元音乘以一个字符串
def exclamation(s):
'string ==> string, returns the string with every vowel repeating four times and an exclamation mark at the end'
vowels = 'aeiouAEIOU'
res = ''
for a in s:
if a in vowels:
return s.replace(a, a * 4) + '!'
上面的代码只是返回'heeeello!'我也尝试过与元音等于交互shell( 'A', 'E', 'I', 'O', 'U'),但使用相同的代码导致了这一点:
>>> for a in s:
if a in vowels:
s.replace(a, a * 4) + '!'
“heeeello ! 'helloooo!'
我怎样才能让它乘以每个元音而不只是其中的一个?
谢谢!我现在看到我做错了什么。完美的作品。 – iKyriaki 2013-02-22 02:44:46