Compare and contrast these two methods for the solution

Hello Codeacademy Python community. For once I am not ranting about a bug that was most likely me just not following directions, haha. I was thinking of comparing and contrasting these two solutions.
Mine:

"""My version of PygLatin.
It has far less variables but the if statement is not as clean and
mine returns false if there's a space :("""

print("Welcome to PygLatin, a Pig Latin translator written in Python")
print("Type in a word.")

word = str(input())

if str.isalpha(word) == True:
    print(word[1:] + word[0] + "ay")

elif str.isalpha(word) == False:
    print('That is not a word. Try again without numbers or symbols')

Codeacademy’s Version:

"""This is CodeAcademy's version of PygLatin
Their if statement is cleaner than mine however
they use many more variables.
"""
pyg = 'ay'

original = raw_input('Enter a word:')
word = original.lower()
first = word[0]
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'
pyg = 'ay'

Demonstrates initial assignment of a string literal constant.

original = raw_input('Enter a word:')

Demonstrates assignment (caching) of user input

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

Demonstrates validation of user inputs using built-in and string method

word = original.lower()

Demonstrates caching of modified original value and use of string method

first = word[0]

Demonstrates assigning a single index (character) of a string

new_word = word + first + pyg

Demonstrates caching string concatenation of defined objects

new_word = new_word[1:len(new_word)]

Demonstrates reassignment of a string slice and using a built-in

print new_word

Demonstrates outputing an object

else:
    print 'empty'

Along with the earlier if demonstrates conditional control flow with default

In summary, every line demonstrates one or more concepts. It does so intentionally since this is a beginner course. It’s far too soon to begin changing things, especially when we are not actually certain of any real improvement.

Publishing our own version in the Q&A is discouraged as it is disruptive and confuses learners, especially when the code is not correct. This topic will be moved to the Corner Bar, presently.

1 Like

I apologize. Should I edit it out?

No, it can stay since it is out of the Q&A, now. You might get some useful replies and food for thought. This is the forum for that.

1 Like

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