python中的基本英语到拉丁语翻译

python中的基本英语到拉丁语翻译,python,Python,我想做一个猪拉丁语翻译 翻译句子(“没有衬衫,没有鞋子,没有服务”)应产生以下内容: Onay irtsshay, onay oesshay, onay ervicesay 这是我的密码: sentence = sentence.split() for item in range(len(sentence)): if sentence[item][0] in "aeiou": sentence[item] += 'yay' else: sente

我想做一个猪拉丁语翻译

翻译句子(“没有衬衫,没有鞋子,没有服务”)
应产生以下内容:

Onay irtsshay, onay oesshay, onay ervicesay
这是我的密码:

sentence = sentence.split()
for item in range(len(sentence)):
    if sentence[item][0] in "aeiou":
        sentence[item] += 'yay'
    else:
        sentence[item]=sentence[item][1:]+sentence[item][0]
        sentence[item]+='ay'
sentence = ' '.join(sentence)

print(sentence)

酷挑战,以下是我的解决方案:

sentence = "hello my name is Ari"

# split words into a list
tokens = sentence.split(" ")

# Iterate over the list of words
for word in tokens:

    # Store the words position in the list for later
    word_index = tokens.index(word)

    # If the first character is a vowel, we'll do this
    if word[0].lower() in ('a', 'e', 'i', 'o', 'u'):
        tokens[word_index] = word + "yay"

    # If it's not we're going to do this...
    else:
        tokens[word_index] = word[1:] + word[0] + "ay"

print(" ".join(tokens))
输出:

ellohay ymay amenay isyay Ariyay

酷挑战,以下是我的解决方案:

sentence = "hello my name is Ari"

# split words into a list
tokens = sentence.split(" ")

# Iterate over the list of words
for word in tokens:

    # Store the words position in the list for later
    word_index = tokens.index(word)

    # If the first character is a vowel, we'll do this
    if word[0].lower() in ('a', 'e', 'i', 'o', 'u'):
        tokens[word_index] = word + "yay"

    # If it's not we're going to do this...
    else:
        tokens[word_index] = word[1:] + word[0] + "ay"

print(" ".join(tokens))
输出:

ellohay ymay amenay isyay Ariyay

请阅读,我将支持@kaya3的主张,即您应该进行审查。在我现在看到的修订版中,这篇文章缺少一个明确的问题陈述——你陈述了你的要求并展示了你的代码——你有问题吗?@tony我们不做家庭作业。请阅读,我会支持@kaya3关于你应该复习的断言。就我现在看到的修订版而言,这篇文章缺少一个明确的问题陈述——你陈述你的要求并展示你的代码——你有什么问题吗?@tony我们不做家庭作业。你不能用
enumerate()
来获取
word\u索引
?你可以,有1000种方法可以剥猫皮,俗话说得好。是的,但是每次使用
index()
获取索引时,听起来工作量很大。:)我们不打算优化这里,它只是一个简单的英语到拉丁语的脚本。当我开始翻译全尺寸的书时,我会考虑你的建议:)但是你的解决方案和OP的尝试逻辑相同,它会产生错误的输出,比如“<代码> < <代码> >。您的解决方案将生成
histay
,但它应该是
isthay
难道您不能只使用
enumerate()
来获取
word\u索引
?您可以,有1000种方法可以剥猫皮,俗话说。是的,但是每次使用
index()
来获取索引听起来工作量很大。:)我们不打算优化这里,它只是一个简单的英语到拉丁语的脚本。当我开始翻译全尺寸的书时,我会考虑你的建议:)但是你的解决方案和OP的尝试逻辑相同,它会产生错误的输出,比如“<代码> < <代码> >。您的解决方案将生成
histay
,但它应该是
isthay