Pyg Latin Error: Why is it throwing this error? I can't set new_word to itself without defining new_word first, right?


#1



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


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


My code runs correctly but it throws an error.


pyg = 'ay'

original = raw_input('Enter a word:')

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


#2

pyg = 'ay'

original = raw_input('Enter a word:')

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

Shoot the middleman. :gun:


#3

correct me if I am wrong, but isn't the line new_word = word a bit redundant? The same can be achieved by just using line
new_word = word[1:] + first + pyg


#4

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