gpt4 book ai didi

python - 我做了一个Python 'robber' s语言的翻译程序,是否正确?

转载 作者:太空宇宙 更新时间:2023-11-04 06:47:38 27 4
gpt4 key购买 nike

<分区>

所以我只是 python 的菜鸟,我正在做这个练习:

"Write a function translate() that will translate a text into "rövarspråket" (Swedish for "robber's language"). That is, double every consonant and place an occurrence of "o" in between. For example, translate("this is fun") should return the string "tothohisos isos fofunon"."

我能够做到这里是我的代码:

def translate (var1):
vaw = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z']
var1 = list(var1)
for string in var1:
if string == string in vaw:
var1[var1.index(string)] = string + 'o' + string
print ''.join(var1)

我想知道这是否正确,或者是否有另一种方法可以用更少的代码来做到这一点?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com