使用 python 构建翻译器。不知道为什么 translation = translation + "G"
Build a translator using python. I don't know why translation = translation + "G"
def translate(phrase):
translation = ""
for letter in phrase:
if letter.lower() in "aeiou":
if letter.isupper():
translation = translation + "G"
else:
translation = translation + "g"
else:
translation = translation + letter
return translation
我不明白为什么翻译=翻译+“G”。谁能帮帮我
translation = translation + "G"
将 'G' 添加到现有字符串 translation
例如。如果 translation = "Hi"
然后 translation = translation + "G"
出来是 "Hi"+"G" 即 "HiG"
我只能说这段代码是什么意思。如果你能告诉我你想要的输出是什么,我可以帮助你更多。
所以代码所做的是它采用 phrase/sentence 并将所有元音替换为 g(如果元音大写则大写 G,如果元音小则小写 g)。
例如。 phrase="欢迎来到 Overflow"
输出 -> 翻译="Wglcgmg tg Gvgrflgw"
def translate(phrase):
translation = ""
for letter in phrase:
if letter.lower() in "aeiou":
if letter.isupper():
translation = translation + "G"
else:
translation = translation + "g"
else:
translation = translation + letter
return translation
我不明白为什么翻译=翻译+“G”。谁能帮帮我
translation = translation + "G"
将 'G' 添加到现有字符串 translation
例如。如果 translation = "Hi"
然后 translation = translation + "G"
出来是 "Hi"+"G" 即 "HiG"
我只能说这段代码是什么意思。如果你能告诉我你想要的输出是什么,我可以帮助你更多。
所以代码所做的是它采用 phrase/sentence 并将所有元音替换为 g(如果元音大写则大写 G,如果元音小则小写 g)。
例如。 phrase="欢迎来到 Overflow"
输出 -> 翻译="Wglcgmg tg Gvgrflgw"