Syntax error in "ending up"


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

original = raw_input('Enter a word:')

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

The last line keeps getting a syntax error. Why?

The error looks like this:

File "python", line 12
SyntaxError: invalid syntax


[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]


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


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


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


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"


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


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


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