#Python - "Pig Latin" Exercise

3 messages · Page 1 of 1 (latest)

proven mist
#

I'm struggling to complete the last test, which assesses an entire phrase instead of a single word. Is there a way I can do this without writing a bunch more code? Here's what I have so far:

    vowels = ['a','e','i','o','u']
    if text[0:2] == 'qu':
        return text[2:] + 'qu' + 'ay'
    if text[0:2] == "xr" or text[0:2] == "yt":
        text += "ay"
        return text
    if text[0] in vowels:
        text += "ay"
        return text
    if text[0] == 'y':
        return text[1:] + 'yay'
    if text[0] not in vowels and text[1:3] == 'qu':
        text = text[3:] + text[0].lower() + 'quay'
        return text
    if text[0] not in vowels:
        if text[1] == 'y' and len(text) == 2:
            text = 'y' + text[0].lower() + 'ay'
            return text
        con = ''
        for x in text:
            if x == 'y':
                break
            if x in vowels:
                break
            if x not in vowels:
                con += x
        print(con)
        text = text[len(con):] + con + 'ay'
    return text```
pastel crag
#

Hi @proven mist 😄

So what you have so far is pig-ifying a single word.

What you need to do for a phrase is break it into a list of individual words, and pigify each word individually. Then, you can glue the words back together into the expected pig latin phrase.

str.split() might be a good place to start: https://docs.python.org/3/library/stdtypes.html#str.split. It returns a list of words.
Once you have a list of words, you can use a for loop around your existing single word logic to process each word in turn.

And if you do that, a one-word list is processed the same as a multi-word list (if that makes sense)...so you can use the for loop around your re-work code for all inputs.

#

Let me know if that helps, and if not - I can provide a more specific hint.