Ending Up Help


#1



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

Getting this error:
File "python", line 10
new_word = [1:len(new_word)]
^
SyntaxError: invalid syntax


pyg = 'ay'

original = raw_input('Enter a word:')

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


#2

This line, you are trying to slice new_word; however the square brackets are not being applied to a string. You need to put the string object you want to apply the slicing to directly before it.


#3

I still don't quite understand, could you please elaborate? Thanks. The lesson instructions specifically used that syntax.


#4

[1:] # the slicing is done straight after the string
a = "string"
a[1:] # again, done straight after the string
a = [1:] # you are not doing it to the string.  You are trying to define
         # a with the equals sign, which is stopping the slicing on the string.
a = a[1:] # now we are redefining a as a sliced at index position 1.

#5

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