Problem slicing


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/1/4?curriculum_id=4f89dab3d788890003000096#


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
    new_word[1:len(new_word)]
else:
    print 'empty'


#2

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


#3

You changed the order of the code.

print original

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

else:
    print 'empty'

#4

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


#5

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.


#7

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!


#8

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:


#9

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


#10

A post was split to a new topic: Slicing problem


#15