Latin Pig error

So here is my kata:

And here is my solution:

And here is the error

Thanks in advance
@cpradio

In short, you are not handling punctuation.

def pig_it(text):
    a = text
    a = a.split(" ")
    c = []
    for i in a:
        if (i.isalpha()):
            c.append(str(i[1:]) + str(i[0]) + "ay" )
        else:
            c.append(i)
    c = ' '.join(c)
    return c

You will only want to move the first letter to the end and add ‘ay’ if the entire word is alpha characters. The above isalpha() check permits that to happen and lets it all pass.

2 Likes

How did you figure out that punctuation thing? I did not even understand the meaning of the error? What does it mean?

The error is it wants your output to be “Oay emporatay oay oresmay !” but your code provided “Oay emporatay oay oresmay !ay” (emphasis mine)

1 Like

Okay so I understand that you made a check on the string if it contains alphabets or not. But what exactly does the else statement does? Can’t figure out that?

If it doesn’t contain alpha characters, you simply need to add the “word”/“punctuation” to the array so when you join it at the end, it is still part of the message. So it is simply adding the “!” to the array without any modification.

But what if we have more than one punctuation in the string then how can we put the punctuation at the desired place?

That would require a bit more work. You’d have to split the punctuation from the word and the re-join them. Most likely using regex to grab the alpha characters and then processing the pig latin logic, then adding the punctuation to the end of the word again.

1 Like

Will give this a try . Thanks man

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.