In Ending Up my code is not ridding of the first letter


#1

pyg = 'ay'

original = raw_input('Enter a word:')

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

When i type "Word" into the translator it gives me an error saying ' It looks like new_word contains "wordway" instead of "ordway"!' i dont know what im doing wrong.


#2

Hello, @petras98!
You should've sliced the string before trying to concatenate it.
What you are doing is:

1) Getting the first letter of the string the user informed.
2) Getting the same string, including the first letter, and concatenating with the first letter and the value stored in the variable named pyg.

Try taking the first letter, doing the slice, on the original string, and storing it on the variable new_word (or another one if you prefer) before concatenating.

Best regards,
g4be


#3

So i got it to get rid of the first letter but now it says ' It looks like you printed the correct translation of "word", but make sure to set new_word equal to the slice as well.'


#4

It seems all you need to do now is to set the

new_word

equal to the slice.


#5

So how would i set the new_word equal to the slice? I cant seem to figure it out...


#6

Yes, that's right!

new_word = insert here the new value you got

#7

So i set new_word = to what the value was, and it worked, but now it doesnt work for any other input?


#8

My new code looks like this:

pyg = 'ay'

original = raw_input('Enter a word:')

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

it allows for me to move on to the next lesson, however my program only works when i type "word" into the program.


#9

Aha! i figured it out! Thanks for your help!!!


#10

Oh! That's because your code only works for such word!
You should've stored the slice of the string stored in new_word into another or same variable.
Example:

new_word = new_word[1:len(new_word)]

Doing new_word = "ordway" is actually not correct.
Remember:

1) word: contains your original string, the one it was informed by the user.
2) first: contains the first letter, [0], of the original word that was informed by the user.
3) pyg: contains the "ay".

So adding them would lead into something like this:
Example:
word contains "c"
first contains "cake"
pyg contains "ay"

Concatenating them into new_word will result into: "ccakeay"
Alter the order to : first + word + pyg so it will turn into "cakecay"
If you do new_word = new_word[1:len(new_word)] it will go from position [1] to the last position so it will get the correct value which is "akecay".

Edit: No problem! Quote me if there's something else I can help you with :slightly_smiling:


#11

Ok will do. thank you again!


#12

All you have to do is set the variable new_word equal to the slice, n thats it, now you have your "ordway" :slightly_smiling: