猪拉丁。将辅音移到末尾的问题,如果单词在我的代码中以一个单词开头

时间:2018-11-11 17:25:20

标签: python

移动辅音的问题,如果单词在我的代码中以一个单词开头,那么辅音会移到最后。

def pig(word):
    pig_const = 'ay'
    pig_vowel = 'way'

    word = word.lower()

    if word[0] in 'aeiou':
        word = word + pig_vowel

    else:

        last_const = ''
        i = 0
        #how many consonents in start
        while last_const not in 'aeiouy':
            i = i + 1
            last_const = word[i]
        word = word[i:] + word[0:i] + pig_const

    return word

print((pig('happy')))

0 个答案:

没有答案