Ending up


#1


https://www.codecademy.com/courses/python-beginner-2W5v7/1/4?curriculum_id=4f89dab3d788890003000096#


pyg = 'ay'
    new_word = [1:len(new_word)]
original = raw_input('Enter a word:')

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


#2

This line should be inside the if code block, under the line,

first = word[0]

However, there is a line missing that will also come before,

new_word = word + first + pyg

Lastly, your slice needs an object

Eg.

x = x[1:len(x)]

#3

I don't know if mtf's suggestions are correct, but I think I found a bit simpler way to do it:

First, like mtf said, move this line new_word = [1:len(new_word)] down beneath first = word[0]

But then, don't use the line new_word = [1:len(new_word)]

This line is overly complicated.

Instead, change this part to ''' new_word = word[1:] ''' #Note that ''' word[1:] ''' will include the first index of word to the last index of word, whatever length the word is.

Bu also.... when creating ''' new_word, ''' you also need to concatenate word[1:] with the first letter of 'word' AND the 'ay'

So this line should be...

new_word = word[1:] + first + pyg

Finally, you don't want to print original. You want this instead:

print new_word


#4

Not if we follow the instructions explicitly. It should be as shown earlier. The slice is the second last step, before printing new_word.


#5

I tried your suggestions and couldn't get them to work, perhaps because I misinterpreted something that you wrote.

But also, did you look at the "Advanced tip?"

It says:

Advanced Tip!
When slicing until the end of the string, instead of providing len(new_word), you can also not supply the second index:

my_string = "Python"
my_string[1:] # "ython"

Based on this suggestion, I thought it was OK to take an approach that deviated from the instructions.


#6

I wonder if you could paste your entire code, verbatim?

I'd like to see how you got it to work according to the instructions because I couldn't get it to work.

Thanks!


#7

Advanced tips are useful once we understand the concepts. To my mind that means completing the exercise as instructed, passing, then modifying.

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

Seeing the slice with both indices demonstrates,

x[start:end]

The advanced slice defaults to end (len(x)) when not specified. It pays to have this clear in one's mind going forward.


#8

I agree with you about Advanced Tips and how we should complete the exercise as instructed. I couldn't get the code to work as instructed, but now I get it after seeing your code. Thanks!


#10

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