Ending up


#1


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

The instruction says -

"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."

So I added [1:len(new_word)] to the new_word formula (see below). I don't understand what I'm doing wrong. Anyone?

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'

#2

You made the mistake here
new_word = [1:len(new_word)]

-> You try to slice the string there, but don't refer to the string you try to slice


#3

Ok I have changed it to the code below. However, is this the efficient/clear way to type the code? Any suggestions are welcome :slight_smile:

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 = new_word[1:]
    print new_word
    
else:
    print 'empty'

#4

Well for this lesson it's fine, in general however, defining pyg = 'ay' while only using pyg once is dumb, instead you would just write new_word = word + first + 'ay' and got 1 less column of code

Defining a variable for a short string, which you only use once aftetwards in your code is something you'd only do for user input


#5

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