Correct code but getting a syntax error


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
10/11 Pyglatin Ending Up

<In what way does your code behave incorrectly? Include ALL error messages.>
I get this error message while it’s considered as a pass.
File “python”, line 9
final_word = [1:len(new_word)]
^
SyntaxError: invalid syntax

<What do you expect to happen instead?>
A fail as the program encountered an error

pyg = 'ay'

original = raw_input('Enter a word:')

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

#2

You need to specify a list/variable containing a list you want a slice of before the square brackets, how else is python suppose to know what to take a slice of?


#3

Hi @blogsurfer41099,

This line is incomplete …

final_word = [1:len(new_word)]

The slice specifier [1:len(new_word)] needs to follow the string that is to be sliced, namely new_word.

Also, to satisfy the requirements of the exercise, you need to assign the solution to new_word.


#4

So I just changed final_word to new_word, passed but I get this

File “python”, line 9
new_word = [1:len(new_word)]
^
SyntaxError: invalid syntax

With ^ pointing to the :


#5

this square brackets:

[1:len(new_word)]

tell python you want to take a slice, but of what? Python has no idea. You need to specify the variable you want a slice of before the square brackets, so python now you want a slice of, in this case, new_word

it is and it never was about final_word


#6

I now understand. From the tutorial all I’m seeing is that there’s just a letter ‘s’ for the variable that contains ‘charlie’ but never recognized it as such. I think it would need to be changed to first_name to show it as such.


#7

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