PygLatin -- error in instructions


#1


https://www.codecademy.com/courses/python-beginner-2W5v7/1/4?curriculum_id=4f89dab3d788890003000096#

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
else:
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.


#2

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

#3

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


#4

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.


#5

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