Is it ok to code like this?


Hi all! I was wondering what difference it would make if I used the following code instead of the code I generated using the step-by-step approach in the lesson?

The code I wrote I did not use the string 'pyg' and 'original', and I did the lower case conversion in line 1.

Is it ok to use the code I wrote? What are the advantages or disadvantages between these two different codes?

Thank you very much for your help!

#The code I try to use
word = raw_input('Enter a word:').lower()
if len(word) > 0 and original.isalpha():
    print word
    print word[1:len(word)]+word[0]+"pyg"
    print 'empty'

#Step-by-step approach
pyg = 'ay'
original = raw_input('Enter a word:')
word=original.lower() #convert to lower case
if len(original) > 0 and original.isalpha():
    print original
    print 'empty'
print new_word


The only difference is this one,

is codecademy's version of a pyglatin translator.

I highly encourage what you have done because it shows you are already thinking like a programmer. The only problem is your code is DRY but it does not print the desired result.

For your code to work you only need to change one line,


print word[1:len(word)]+word[0]+"ay"

And also you don't need this line anymore,


Can you elaborate on this?


DRY stands for don't repeat yourself. For example in the codecademy lesson you have:

original = raw_input('Enter a word:')

while you could do this in one line (like you did), so you don't repeat yourself, is meant as a positive thing (your program is more efficient), just make sure it stays readable :slight_smile: (which you did)


The only problem is it didn't print the desired result which I elaborated as well.


i know, but it seems OP didn't seem to know DRY (despite applying these principals), so i thought it would be more valuable for my answer to talk about DRY, you already mentioned these mistakes.


Sorry I thought I sent it to @supernovaderek :sweat_smile:


I got it! Thank you both @bandit @stetim94!!