<pre><code>word = input("Translate a word: ")
for char in word:
if char in "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz":
print(char + "o" + char)
else:
print(char)
</code></pre>
<p>我有一个翻译语言的代码,在每个辅音后面加一个“o”,然后再加上同一个辅音。当我运行它并键入例如“stair”时,它会打印出来:</p>
<pre><code>sos
tot
a
i
ror
</code></pre>
<p>如果有人有一个想法,如何打印在同一行没有间距,我会非常感激!你知道吗</p>
<p>不要每次都打印,而是将结果附加到字符串并打印最后一个字符串:</p>
<pre><code>word = input("Translate a word: ")
result = ''
for char in word:
if char not in "aeiouyAEIOUY":
result+=char + "o" + char
else:
result+=char
print(result)
</code></pre>