Correct translation but slice not equal


#1

Hello, I have this error message:

Oops, try again. It looks like you printed the correct translation of "cyril", but make sure to set new_word equal to the slice as well.

This is my code:

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

I forgot to declare something?

Thanks for your help.


#2

you need to store the slice in new_word (updating new_word so it contains the correct translation), and then print it on the next line without any further manipulation while printing


#3

I read several topic, I changed my code few times but sorry, I don't see where I must updating "new_word".


#4

here:

print new_word[1:len(new_word)]

you should update new_word so it contains the slice, then on the next line print new_word


#5

Like that?

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


#6

better, but when you take the slice, you need to store result of this action in new_word, updating the variable


#7

This variable?

new_word = word + first + pyg


#8

yes, but we can updated variable:

x = "hello"
x = x + " world"

you need to update new_word so it contains the result of the list slicing action


#9

Sorry I'm a noob.

I did that:

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


#10

i just showed how to update a variable? In your case, the updated variable should contain the slice, no need for new_word +

just because a concept, doesn't mean you have to use that exact same syntax...


#11

I found how to do finally :slight_smile:

Thanks for your help.


#12