Need help with my Pig Latin translator


#1

Hi all I am new to programming and recently did the Pig Latin Translator exercise here. I tried to replicate in Atom. if it makes a difference I am using Python 3. instead of Python 2. like the exercise uses.

Here is what I have:

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

original = input('Enter a word: ')
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
print(new_word)
else:
print(‘Try again.’)

However I keep getting this error:
Traceback (most recent call last):

File “piglatin.py”, line 2, in <module>

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

Any help would be greatly appreciated!


#2

That line should not be at the top of the program. It can be removed.

Assuming the line above has been removed, new_word is as yet undefined.

You have pyg and first strings, plus a lowercase word string. Assemble these as per instructions then define new_word. At the last step, use the slice syntax to finalize the program.


#3

Thank you very much! it works now.