对于我的类,我遇到了一个很难回答的问题,我需要用Python为给定的字符串创建一个Pig-Latin转换器。在
基本上,规则如下。在
对于任何以一个或多个辅音开头的单词(y被认为是辅音): 将辅音移到单词的末尾,并附加字符串“ay”。
对于所有其他单词,在末尾附加字符串'way'。
不管怎样,我们发现,对于元音这个词的功能,我们都要找到一个独立的功能,不管怎样,我们都要用它来处理元音的功能,我很难在我的主要公式中实现大小写和标点符号,以及如果一个单词没有元音该怎么办(因为在我们的例子中“y”不算元音,“my”这个词没有元音。在
这是我目前为止的代码。在
def vowelfinder(astring):
vowels = ["A","E","I","O","U","a","e","i","o","u"]
alist = astring.split()
for i in alist:
for j in range(len(i)):
if i[j] in vowels:
print(j)
break
def igpay(astring):
vowelfinder(astring)
for i in alist
任何建议都是有帮助的
这是一句话。分词应该很容易。在
编辑:脑屁。在
相关问题 更多 >
编程相关推荐