Syntax error in "ending up"


#1



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

in "Ending up" I am putting in
pyg = 'ay'

original = raw_input('Enter a word:')

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

The last line keeps getting a syntax error. Why?

The error looks like this:

File "python", line 12
    [1:len(new_word)]
      ^
SyntaxError: invalid syntax


#2

[1:len(new_word)] is used to take slices from strings, but python needs to know of what you want a slice. You can't just walk into a cake shop, and say: i want a slice.

so we need to specify of what string we want a slice, we do this by placing the string (or variable containing a string) before the square brackets:

"hello world"[0:6]

#3

Great, but now I'm still getting an error.


#4

new_word is a variable, not a string? I just demonstrated it with a string. I showed you a concept.


#5

I don't really understand what you mean. do you mean to make it a string using str?


#6

new_word contains a string, i demonstrate how to take a slice of a string, but you can also take a slice of a variable containing a string:

x = "hello world"
x[0:6]

#7

I still don't understand what you are saying for me to do.


#8

your new_word variable contains your translated (pyglatin) version of the user input, of which you need to take a slice


#9

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