我試圖把一個字符串作爲輸入,並返回相同的字符串,每個元音乘以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