+ 1
Pig Latin HELP
en = input() wl = list(en.split()) for i in wl: a = wl[i] a += a[1] a += ('ay') a = a[i][1:] print(str(wl)) It says a = wl[i] is wrong WHY?
4 odpowiedzi
+ 7
en = "Hello World"
en.split() would split it by words and return a list with the following elements -
['Hello' , 'World']
So if there's only one word in the input, there will be only one element in that list. So w[1] will give an "index out of range" error.
What you are want is to split the word by "letters". For that,
Replace the 2nd line with -
wl = list(en)
And it should work.
Tell me if it works for you after trying this.
+ 2
Ooooh, I got it! I forgot that the first element is [0] but not [1]
+ 2
Here is final code:
en = input()
wl = en.split()
word = 0
for i in wl:
wl[word] += wl[word][0]
wl[word] += 'ay'
wl[word] = wl[word][1:]
word += 1
print(' '.join(wl))
+ 2
Oh, haha. Glad you got the answer.