成功地做了一个单词翻译功能,并且从我的班级里看到其他人做了什么我知道我需要在句子功能中分割句子参数。但我不知道该怎么办!我使用http://www.mit.edu/~johnp/6.189/solutions/piglatin.py作为参考(然而,它是python 2)来帮助我理解这一点,并且我理解它,但是在list_of_words后我完全失去了。是的,我已经看过其他猪拉丁语的问题,但我不认为我能够理解,甚至看不到我应该从这里进入什么方向。Python 3猪拉丁语句子
对不起这是一个很大的要求,我不希望你来回答这个问题,我只是想在做什么
consonants = "bcdfghjklmnpqrstvwxyz"
def pig_latinify_word(word):
fist_letter = str(word[0])
if first_letter in consonants:
return str((word[1:] + word[0] + "ay".lower())) #I think the str() is
else: return str((word + "way".lower())) #arbitrary, but not sure. Being safe!
def pig_latinify_sentence(sentence):
list_of_words = sentence.split()
new_sentence = "" #the bit where I am stuck. Understand up to this point.
for word in list_of_words:
new_sentence = new_sentence + pig_latinify_word(word)
new_sentence = new_sentence + ""
return new_sentence
piglatin = pig_latinify_sentence("This is a about to be a piglatin sentence")
print(piglatin)
很抱歉,如果这仅仅是一个讨厌的转贴的方向指出,但我已经看了几个答案,我不知道从这里开始做什么。另外,我想补充一位导师说我不需要分开辅音,尽管在我看到的其他例子中。可能与它有关系吗?我不知道!不管怎么说,还是要谢谢你。
编辑:我想我可能找到了一个答案,显示我需要从这里改变,但我不明白。还有人在教科书中查找某些东西是很好的。我只是想阅读和理解,我知道它可能有点多问。
编辑:哦,我的上帝,刚刚意识到这是一个错字。 fist_letter,而不是first_letter。
谢谢!我会重读你的答案。