擅长:python、mysql、java
<p>让我们逐行注释:</p>
<pre><code> s = input () #wrong indentation
s.lower() # you have to assign it to s.
for i in range (0, len(s)): # range(0, x) is the same as range(x)
if (s[i] in "aoyeui"): # ok
s.replace(s[i], '') # strings are not mutable so replace does not modify the string. You have to assign it to s
# splitting can be done much easier :)
for i in range(0, len(s)):
s.replace(s[i], '.' + s[i]) # again you have to assign
print(s) # ok
</code></pre>
<p>我也注意到你的代码还有一个问题。当替换元音时,字符串长度会发生变化,并可能导致多个问题。当长度改变时,通常不应该按索引进行迭代。所以正确的代码应该是这样的:</p>
<pre><code>s = input ()
s = s.lower()
for vowel in "aoyeui":
s = s.replace(vowel, '')
s = '.'.join(list(s)) # this is how to separate each character with a dot (much easier eh?)
print(s)
</code></pre>