I'm going through the Pig Latin code converter with a link to the lesson below:
My code runs and behaves correctly, however I think i've only written a basic form for the solution. Are there any advanced tricks to optimise the code?
I'm hoping to reach this level of proficiency someday
def pyglatin(): # variable definitions user_input = raw_input('Enter your first word to translate:') if (len(user_input) > 0) and user_input.isalpha(): print "You typed %s" % (user_input) pyg = "ay" word = user_input.lower() first = word new_word = user_input pigword = word[1:len(user_input)] new_word = pigword + first + pyg print "The word in piglatin is %s" % (new_word) return True else: print "The word you entered is invalid, please try again" pyglatin() print 'Welcome to the Pig Latin Translator!' pyglatin()