10. Ending Up || Help, please


#1



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


I've tried all that I've seen here on the Forum, but I've yet to figure it out.
Oops try again, Your codedid not run to the end - see the console window for the error message.
Traceback (most recent call last)
File "python", line 8, in
NameError : name 's' is not defined.


I expected it to work, yet here I am


pyg = 'ay'

original = raw_input('What is your name?')

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


#2

Yeah so the example in this can be misleading. You do not need an s to perform and create this code correctly.
First, you need new_word to equal the complete word through the pyg. Instead of [1:len(new_word)] you want word. This is because word will give you the word put in the input and when put together with + first + pyg you will get the word in pig latin. Next, you need new_word equal to [1:len(new_word)]. Now the tricky thing with this is you cannot just set [1:len(new_word)] equal to new_word. Finally, instead of printing original you need to print the combination that new_word is equal to. So your basic outline to fix this should be like this:

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

You can figure out what to solve the lesson.


#3

lright-aay, ibleman-bay. hank-tay ou-yay :smiley:


#4

hahay adgay tay lphay :smiley:


#5

pyg = 'ay'
original = raw_input('Enter a word:')

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


#6

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


#7

huh?
hank-tay
ou tay


#8

I don't understand why there is a "what" placeholder before [1:len(new_word)]. what is not a defined variable in the code above so what are you indexing against? For example below is the code I've entered, but keep getting the same error:

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

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[1:len(word)]
    print new_word + first + pyg
else:
    print 'empty'

How is this wrong? It gives the exact output that I need for the correct pyglatin translation.


#9

Well first off, you need to new_word to equal new_word + first + pyg to get the new_word to show us the pig latin translation. Secondly, you then need new_word equal to new_word[1:len(new_word)] not word. The word just represents the "old" or original word but the new_word is the one you wanted printed which is the pig latin translation. Also, if you just put new_word = [1:len(new_word)] Python does not know which word to slice. Now you print new_word[1:len(new_word)] to get the new pig latin word up on the computer screen.


#10

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