10/11 Ending Up


#1



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

File "python", line 9
new_word = [1:len(new_word)] + first + pyg
^
SyntaxError: invalid syntax


I'm not sure what I'm doing wrong, could someone please explain it to me?


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)] + first + pyg
    print new_word
else:
    print 'empty'


#2

 File "python", line 9
 new_word = [1:len(new_word)] + first + pyg
 ^

just see the example in this lesson how to access a slice of string.


#3

The SyntaxError happened is because you assign the variable of new_word wrong. So you have to assign the variable like i did.


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'

#5

you forgot to put 'word' before the array [1:len(new_word)].


#6

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