4/10 Ending Up is Making me End Up Sad


So so far in my code what I've gotten is:

I know that you're supposed to pyg = 'ay'

original = raw_input('Enter a word:')

word = original.lower()
first = word[0]
new_word = word + first + pyg

if len(original) > 0 and original.isalpha():
print original
print 'empty'

Basically I'm a tad bit stuck on where to go next with this code, it says to:

Set new_word equal to the slice from the 1st index all the way to the end of new_word.

and then to use: [1:len(newword)] to do this._

So I guess more or less I'm just wondering how and where the [1:len(new_word)] feature comes into play within my code.


What the [1:newword] does, is to give you the word, starting from the 2nd letter, so you could use it at the end of the progress, like:

and make it:

new_word = [1:newword] + first + pyg


Alright thanks a bunch! That seemed to help me get through the lesson!


Bear in mind that the above is not what the instructions direct.

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

It's minor in long run, but we should still make every effort to follow the exact instructions, especially when given a clear example.


Do you mind explaining why you need the new_word before the [1:len(new_word)]
I'm pretty confused on this part. Thanks.


We created the new word by first concatenating all three string variables and assigning it to new_word. This step was in the instructions, as is the next, to which you refer.

new_word, being a string object is iterable, meaning it has an index. [1:len(new_word)] is such an index of the iterable it is attached to.


a = "string"
print a[0]           # s
print a[1:len(a)]    # tring

Notice that [1:len(a)] is only a slice of a if it is called on a. Not having an iterable to slice from, would raise an error, one would think.


2 posts were split to a new topic: I still need help


Hi! For me this worked:

> pyg = 'ay'

> original = raw_input('Enter a word:')

> if len(original) > 0 and original.isalpha() and original.lower():

> word = "love"

> first = "love"[0]

> new_word = word[1:4] + first + pyg


> print original


> else:

> print 'empty'

Hope you can use it :slight_smile: