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.
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)
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.
Will give this a try . Thanks man
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.