<p>在问这个问题之前,我已经检查过我的问题是否有解决办法。在</p>
<p>我在做Python。我正试图编写一个输入字符串的代码,对于该字符串中的每个字母(元音(<code>aeiou</code>),将该元音本身替换4次。然后在末尾添加一个感叹号(<code>!</code>)。示例:</p>
<p><code>apple</code>看起来像<code>aaaappleeee!</code>。在</p>
<p>我试了很多次都没有效果。不知道你们能不能看看我的代码看看我做错了什么。拥抱和亲吻。克里斯托弗</p>
<pre><code>def exclamation (string):
for i in range(0,len(string)):
if string[i] in 'aeiou':
string.replace(string[i],string[i*4])
print(string + '!')
</code></pre>
<pre><code>def exclamation(string):
new_string = ''
for c in string:
if c in 'aeiou':
new_string += c * 4
else:
new_string += c
new_string += '!'
return new_string
</code></pre>