-2

I wanted to code a program that changes the word order: Hello --> elloHay.The input is a string like " Hello World". However,it doesn't work. I am thankful for your help.

def pig_it(text):
    a = text.split()
    for i in range(len(a)):
        a.map(i[0])
        for i[0] in a:
        t = i[:1]+ i[0] + 'ay'
    a = " ".join(t)
    return i
  • Why are you returning `i`? `i` is a number from your range. You also seem to be trying to slice it as if it is a string. – khelwood Apr 21 '21 at 11:05
  • I think what you mean is that you want to reverse the string, i.e., "Hello" becomes "olleH". If that is what you are looking for there are dozens of ways to do it. For a complete answer on the subject see https://stackoverflow.com/questions/931092/reverse-a-string-in-python – Eduardo Apr 21 '21 at 11:33
  • Sorry,I forgot to tell you .The input is a string consisting of more than one word – Nothing Else Apr 21 '21 at 11:46
  • Does this answer your question? [Converting a sentence to piglatin in Python](https://stackoverflow.com/questions/23177250/converting-a-sentence-to-piglatin-in-python) – samuei Apr 21 '21 at 14:42

1 Answers1

0

Try this:

def pig_it(text):    
    return text[1:len(text)]+text[0]+'ay'
Nir Elbaz
  • 556
  • 4
  • 19