What's wrong with the 'ending up' ? HELPPP~



pyg = 'ay'

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


Can you post the error you are getting?


'Enter a word: d

Then it said:'Oops, try again. It looks like you printed the correct translation of "d", but make sure to set new_word equal to the slice as well.'

I don't know What it means and What I should do...T-T


Okay, what it's asking you to do is rather than call:
print new_word[1:len(new_word)]
It wants an extra line which assigns the slice to the variable new_word. You can do this by rearranging your code thusly:

new_word = new_word[1:len(new_word)]
print new_word

So technically your code is fine, but the lesson specifically wants you to store the slice in new_word before you do anything with it.


Sorry..but now I also don't know how to edit the code...:sweat:


Can you not just use the link you posted above and change the code you have in there?


Yes, and how to change it ,

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

How to deal with two lines above, if change as "new_word = new_word[1:len(new_word)]
print new_word" ,
What about the first "new_word " ?


Okay, so in your if statement where you first define new_word, you want a line afterwards which redefines new_word as a slice of itself. That may sound confusing, so I've annotated the code you want:

if len(original) > 0 and original.isalpha():
    first = word[0]
    # First, create new_word as you would normally:
    new_word = word + first + pyg
    # Now, redefine new_word as a slice of itself:
    new_word = new_word[1:len(new_word)]
    # Now you can print new_word without having to alter it:
    print new_word

As I said before, your original code is technically fine, but suppose you wanted to print out the result multiple times - you'd have to write out print new_word[1:len(new_word)] every time! This is why the lesson wants you to store it in a variable so you only have to write print new_word.