Decided to make a translator that takes Pig Latin and translates it to English


Here's the code I used. Would love any suggestions for improving it or making it more elegant.

original_pyg = raw_input('Enter a word in Pig Latin:')
less_suffix = original_pyg.lower()[0:(len(original_pyg)-3)]
new_word_pyg = original_pyg[len(original_pyg)-3].upper() + less_suffix

if original_pyg.isalpha():
if original_pyg[len(original_pyg)-2:len(original_pyg)] == 'ay':
print 'English translation: ' + new_word_pyg
print 'Oops! Are you sure you entered a word in Pig Latin? It doesn\'t seem to end with \'ay\'...'
print 'Oops! Looks like your string contains spaces or non-alphabetical characters. Please try again.'


Let's try this!

def igpay_otay_nglisheay(ordway):
    return ordway[-3] + ordway[:-3]

Also we need this

def pig_latin(word):
    return word[1:] + word[0] + 'ay'

So then we do,

a_word = pig_latin('Goffy')
# OUTPUT: offygay
# OUTPUT: goofy

Seems to work for me, you can of course add checks and such but this is the base needs for this code to work.


For flavor you could override the base def/return and any other key word into piglatin for the FLAVOR!