Break it down

I don’t have a clue to how you would put the first letter at the back of the word. Please help

Try this in a Python shell, maybe this will help you:

word = raw_input()

make the word to a list and then append it at the end.

I’m relatively new to python and I may just be being really stupid. This is my code:

print “Welcome to the Pyn Latin Translator!”
word = str(input(“Please input one word you would like to translate:”))
word1 = (word[ :-1])

I typed in hello in the command block and this error message comes up:

Traceback (most recent call last):
File “python”, line 2, in
File “”, line 1, in
NameError: name ‘hello’ is not defined

I thought i had defined hello as word but I don’t know how to fix it.

First of all, you’re not stupid! Just unexperienced :slightly_smiling:

Now, lets start to analyze your code:

input() will only take integers (numbers) as an input, and the str() will just turn the number into a string, which won’t help in this case, because we want to have a word as an input.
Let’s type raw_input() instead of those two, which will take in a string :smiley:

Hmm… this won’t do anything. I think you wanted to make this the first letter of the word, which you wanted to put at the end of the new word, so let’s assign it to a variable first, so we can use it later on :smiley:

first_letter = word[0]

word1 is supposed to be the new word, right? But if you make it word[:-1] , it will take the whole word, without the last letter, instead of the first letter, we wanted to leave out.

Try this instead:

word1 = word[1:]

This will take the whole word, starting from the 2nd letter of the word.

Now the only part, left to make the pyglatin would be the “ay”, so let us define that one too:

pyg = "ay" (not sure how you name the variable, read that one from the instructions please :slightly_smiling: )

I hope this helped you :smiley:

1 Like

The problem is caused by the fact that you use input:

word = str(input("Please input one word you would like to translate:"))

but input is a python3 function, codecademy uses python 2.7.x (i believe the x is 3, but not sure, that is why i put x), in python2.7 you should use raw_input:

word = str(raw_input("Please input one word you would like to translate:"))

Thanks @stetim94 and @frozentofu. See, at school we use Idle and Shell on the computer’s system and on that you are able to write input() to get words.

which means that system runs python3, there are some differents between python2 and python3, raw_input and input is one of them, another one is print, in 2:

print "hello"



There are more differences, keep an eye out for these differences on CC and idle/shell

1 Like

please help im stuck on word up i just want to punch this computer

@goricav, yes, you are but only if the rest of your answer is constructive/explanation to the code

@stetim94 I’m posting it again since I was unable to just edit previous post. I hope this is what you meant.

print "Write an English word" #quoted text will be displayed in the console
eng_word = raw_input() #this is a way to take a user's input 
pig_word = eng_word[1:] + eng_word[0].lower() + "ay"
print pig_word

`They said “take a first letter of the input word and let it be lower case”, so I took it with eng_word[0] and made it lower case using .lower() method: eng_word[0].lower()
Then, they said “add ‘ay’ to the end”, so I did it… + “ay”
We also have to leave the rest of the input word, which is everything except first letter, and we do it like this: eng_word[1:]. Remember that counting starts from 0, and we already took 0th element in the step 1.

In the end, you just print the new word.


A post was split to a new topic: Break it down