Pyg Latin 10. Ending Up don't understand error message


#1

This is my code:

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

else:
print 'empty'

This is my error message:

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

I don't understand how this can be a a syntax error as I copied [1:len(new_word)] directly from the instructions.

I have checked the other threads for this exercise and found no answer.

Thanks for any advice.


#2

@bigdavidginola
You have to much going on here, let's simplify this a little!

The PROBLEM!!!

Problem: Take a word, moves it's first letter to the end and then add 'ay'

Ok so lets ONLY do that!

word = 'word'
print(word[1:] + word[0] + 'ay')

Easy enough, now lets add this to your code!

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print(original[1:] + original[0] + 'ay')
else:
    print('empty')

There now that looks a lot better!

Your Error!

new_word = [1:len(new_word)]

This is not doing anything useful at all...

new_word = new_word[1:len(new_word)]

That should do something if you call on the correct variable!


#3

Dear Zeziba

Thank you for taking the time to help. I see how your solution works. However, it is a very radical change from the code the exercises starts with:

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
print word

else:
print 'empty'

Also, the instructions specifically state: Set new_word equal to the slice from the 1st index all the way to the end of new_word. Use [1:len(new_word)] to do this.

In any case, trying your solution:

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():

word = original.lower()
print(original[1:] + original[0] + 'ay')

else:
print 'empty'

gives error message: Oops, try again.
It looks like you printed the correct translation of "hello", but make sure to set new_word equal to the slice as well.

I encountered this error message when I tried my originally posted code but with
new_word = [1:len(new_word)]
print new_word

changed to
print new_word [1:len(new_word)]

I have found a solution on https://www.codecademy.com/forum_questions/53d3410052f8634d6a000214.
This requires another change from what the exercise expects, changing the code to:

first = word[0]

second = word[1:]

new_word = second + first + pyg

final = new_word

print final

However, the code allows me to get past this stage.

Thanks


#4

@bigdavidginola

I get their point they wanted to show you each step individually.

Though i think it is pointless to have all the extra stuff. It does add tons of confusion, just look at all the other post about this same issue and you will notice a trend.

While it is all good and well they are doing this for "free" it could do with some improvements.


#6
pyg = 'ay'


original = raw_input('Enter a word:')
#if length of original is greater than 0 and is alphabit
if len(original) > 0 and original.isalpha():
#Lower word
    word = original.lower() 
#First = the first letter of word    
    first = word[0]
#New_word = word + first letter + pyg    
    new_word = word + first + pyg
#new_word = everything after the second letter of new_word to the length of new_word    
    new_word = new_word[1:len(new_word)]
#print new_word(translation) and original word
    print original
    print new_word
else:
    print "nothing"

#7

This helped me. I realized I wasn't setting new_word = new_word[1:len(new_word)]

I had forgotten to include the reassigned variable at the front of what the new word would be.

Thanks!


#8

THIS WORKES!


#9

omfg works not workes


#11