There are countless ways we can write this program. The instructions for the exercise break it down to a step by step procedure, even as the code is built. We started out with a basic condtional just to set the framework...
pyg = 'ay'
original = raw_imput("Enter a word: ")
if len(original) > 0:
print original # temporary
Further to this, we next added text validation to the conditional.
if len(original) > 0 and original.isalpha():
The last steps replace the
print original statement with the procedural code. Again, step by step creating the
word = original.lower()
This is sensible since it preserves the original. Only the working value is mutated. A couple more steps and the new string will be built in the raw.
first = word # intermediate step
new_word = word + first + pyg
Because we have defined
new_word we can now write exactly what the instructions ask for...
new_word = new_word[1:len(new_word)]
The above notwithstanding we can refactor the code, after we follow the instructions and pass.
new_word = new_word[1:]
is an identical slice. Notice that the lesson expounds upon this fact by showing the similarity. If we only ever saw the latter form, we might never fully comprehend what value is implicitly included in the short form slice syntax. The joys or introductory lessons.
There is much joy in paring code down to its simplest form, once we know the logic and procedures are correct.
return ("%s%say" % (term[1:],term)).lower()
print pyg_latin("Codecademy") # odecademycay
This probably won't pass the exercise, but it definitely works as expected.