It works! But


#1



PygLatin Exercise 10


My code completes the job of translating the word to pyglatin, but I get the following message"

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


If it works why do I get this message? It looks to me like I have set the new_word equal to the slice.


pyg = 'ay'

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


#2

Correct result, wrong presentation. Refer to instructions/error message for what you were supposed to do with the result.

This is like in a math test where you get half score because you said "5" instead of "5 apples"


#3

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

The variables WORD, FIRST and NEW_WORD have to be inside the if statement, as shown on mine. There is a very good reason for that. Firstly, it's what the instructions tell you to do. But also, you need to learn about global and local variables. Global variables are introduced outside of IF statements and functions. They always work. But local variables are introduced inside an IF statement or a function. They are different because they only work inside the function in which you created them. So if you were to use it outside of that function, you would get an error because the variable is undefined. Now, why would you want to have a local variable rather than a global one? Because sometimes that variable would only be relevant in one function and nowhere else. This is not the case in this scenario, but codecademy is trying to teach you to be EFFICIENT with your code.
I hope that explains things :wink:


#4

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