Ending up - stuck with invalid syntax


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

this is what I got as answer.

and below is my code

Please help - I just cant understand why ":" is treated as invalid syntax.

thank you,

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)]
    print new_word = [1:len(new_word)]
    print 'empty'


Why are you setting new_word equal to a slice of new_word and printing it in the same sentence?


I've understood it as if I will set it again then the new_word will just be a new variable with different input. Should I delete this line?


Yep, clean up line 8.


Thank you, I did it,

Unfortunately, I still have the same problem - it is showing that ":" is invalid syntax in new_word = [1:len(new_word)]


If the syntax error points to the colon, it doesn't mean that the error is there. But this is your last problem:
You must slice new_word with [1:len(new_word)] instead of setting it equal to new_word.


Thank you, got it. I just didn't realise that I wasn't slicing it before naming it.

Thank you once again! :slight_smile:


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