Problem slicing


I can't figure out what I am doing wrong. Can anyone help?

pyg = 'ay'

original = raw_input('Enter a word:')

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


your above line should be equal to something as well :thumbsup:


You changed the order of the code.

print original

It goes below all the code, it is above only of:

    print 'empty'


what? No? He should store the slice he is taking into new_word (updating the variable) so that new_word contains the correct translation so he can print it in the end


Everything looks fine, but I think you forgot to print new_word[1:len(new_word)]. Without it, your code will just show what you input into original and won't show it in pyglatin. It also won't show because everything ( word + first + pyg (the parts to make your pyglatin)) is contained in it too. So basically, you really need to print that to get it to work the way Codecademy wants it to. I hope it works :slight_smile: and I hope I am correct.


yeah I realize that. I had always done that through new_word = new_word[1:len(new_Word)] I did not realize that you could do it without the equal sign therefore my comment but as I am reading now I am learning you don't have to. xD My bad!


Yeah when I had to do that lesson, they would not let me do it without assigning it to something. It worked perfectly without assigning (=) to it piglatin-wise, but they wouldn't let me continue unless I = the slice for some reason, and when I did it, it displayed the word incorrectly even though it let me pass. So yeah, @stetim94 is right about that. :slight_smile:


the exercise wants that new_word contains the pyglatin translation, so you can print it without any further manipulation, its the only way you can get through


A post was split to a new topic: Slicing problem