PygLatin testing Code is accepted, but doesn't work


#1

Code here

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

It worked the very first time on the step before, but when I tested it again it used the same word from the last slide instead of the new one I typed in. After that No matter the word it kept thinking the first letter to add to the end was from the previous word.

Example: new word: "Hello" previous word I tried: "Dog"

output: "elloday"

Then if I tried say "Shirt" after it would give hirthay.

Is this an error in my code?


#2

Figured it out, word was being defined after first rather than before.


#3

In procedural code, order of operations is important. The first line in the program can define the working constant:

pyg = 'ay'

Next we prompt for input:

original = raw_input('Enter a word:')

Next we test and validate the input:

if len(original) > 0 and original.isalpha():

Now we can manipulate the validated text.

    word = original.lower()
    first = word[0]

Now follow this with the remaining lines (the two assignments and the print) and close out with the else statement.