GOT STUCK in Ending Up


#1


here is my code and I run it while the result is that

Oops, try again. It looks like new_word contains "aaay" instead of "aay"!

so where the problem is? why I got a letter "a" twice?

THANKS A LOT!


pyg = 'ay'

original = raw_input('Enter a word:')

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


#3

WOOPS
seem the problem is not I got an "a" twice

to be more specific

please just see the example

when the input is the word "cake"
the print is "cakecay"

so the first letter appears twice? in the begin and the end of the word?
who can help me?
Thanks!


#4

This line:

new_word[1:]

does not change the value of new_word :slight_smile:

You have to assign returned value to the variable to make the change:

new_word = new_word[1:]

#5

ohhhhhhhhh
I got it!
THANK YOU!


#6

You're very welcome :slight_smile:


#7

thanksssssssssss very much


#8

Thank you for explaining, however I do not understand from the instructions how we had to change the variable " new_word ". I don't think they made this clear enough on how to type this out?


#9

Basically i mean why is the [1:] needed after new_word? i do not understand that portion!


#10

Quote from instructions:

Set new_word equal to the slice from the 1st index all the way to the end of new_word. Use [1:len(new_word)] to do this.

But the default value of the end index is the last index, so we can write [1:len(new_word)] as [1:].


#11

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