PygLatin -- error in instructions


Instructions say:

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.

Therefore, I wrote the code as follows:

pyg = 'ay'

original = raw_input('Enter a word:')

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

Following error results:
Traceback (most recent call last):
File "python", line 8, in
NameError: name 'new_word' is not defined

According to instructions, it appears as though I should set new_word as follows:

new_word = word[1:len(new_word)] + first + pyg

This causes the previously mentioned error.

Correct code appears to be:

new_word = word[1:len(word)] + first + pyg

Instructions should be corrected to ask to use [1:len(word)]

Replace this line with your code.


If we build new_word according to the instructions,

new_word = word + first + pyg

Now it is defined and we can take a slice of it.

new_word = new_word[1:len(new_word)]


Ah, I see. Seems inefficient, but ok. :stuck_out_tongue:


It's what the instructions ask for. This is way too soon to put any concern into efficiency. Learn the code and its syntax and leave efficiency concerns for later.


hi, i found a easy way like this:
word = raw_input("please enter a word:")
newword=word[1:] + word[0:1]+"ay"
print newword