Can't succeed in Ending Up tab from PygLatin


Exercise: Ending up

Output is given which is same as my input. Also can't understand the logic of executing the program. Specially these two lines:
new_word= word + first+ pyg

pyg = 'ay'

original = raw_input('Liverpool')

if len(original) > 0 and original.isalpha():
    word= original.lower()
    new_word= word + first+ pyg
    print original
    print 'empty'

Help will be heartily appreciated! :slight_smile:


acc to me it should be like this

new_word = word + first + pyg
new_word = word[1:len(new_word)] or new_word = word[1:]

now explaination

here     word = liverpool
            first = l
            pyg = ay

hence first line output is liverpoollay (here lay is added at the end)

now we need to remove the first letter of the word as we have sent it to the back
for that we wrote next line
which sliced the word liverpool ( l is at 0 position, and we stored new_word as from 1 postion to the length of it)
hence final output should be iverpoollay
if still didnt get ask again... all the best


while you are chopping off the first letter with that first line of code, you are not actually using that chopped bit for anything as the next line just adds together your original+first letter+ay. so the first thing I would change is the order those bits of code appear in.

The part about chopping off the first letter needs to be done on the finished product. The comment above me does not actually chop off the letter of the new word as he is chopping the original word.

the proper bit of code should be
-you are adding the word +its first letter+ay

-This second line will overwrite the "new_word" variable with the chopped version.

The reason your output is the same as the input is because you have "print original" . If you want to see your new word "print new_word".


Everyone, if you want to help somebody with a problem I honestly think it'd really be best to work WITH the original code. Not write completely new code. It impedes the learning process for many of us! Given that, here's what I got and I passed using this code.

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
new_word = original[1:len(original)] + first + pyg
print new_word
print 'empty'

Allow me to explain as best I can.

new_word is a function and you can make it do whatever you want.

My name is Derek.
original = Derek

[1:len(original)] = "erek"
first = "d"
pyg = ay

I made sure to print new_word, not original, like they wanted.

Hope this helped.


Fantastic sir! Thank you very very much!


I wrote the following program ---

Pig Latin translator

original_word = raw_input("Please enter a valid word -> ").lower()
first_word = original_word[0]
add_word = "ay"
new_word = original_word + first_word + add_word

function that translate the word to piggy word

def pig_latin(word):

# check the conditon
if (len(original_word) > 0) and original_word.isalpha():
    pig_word = original_word[1:len(new_word)] + first_word + add_word

    print("Your original word was {}.".format(original_word))
    print("And the 'Piggy' word is {}".format(pig_word))
    print("The word you entered isn't appropriate.!")

execute the method


It is basically saying that take the length of the 'original_word' variable from the 2st place onward, that is value at index[1], up till the length of the 'new_word'.


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