Ending up - stuck with invalid syntax


#1

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,
Joanna


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)]
else:
    print 'empty'


#2

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


#3

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?


#4

Yep, clean up line 8.


#5

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


#6

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.


#7

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

Thank you once again! :slight_smile:


#8

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