A real PygLatin translator


#1

The translator as the lesson dictates does not account for situations that would create gibberish. Namely when the input words start with a vowel or with a th, ch, wh. Take for example the word arrow. if input into the code as instructed you would get rrowaay which makes no sense. likewise a word like chocolate also has issues with the current translator returning hocolatecay. A true translator must come up with conditions to handle these exceptions. I offer the following code. arrow returns arroway and chocolate returns ocolatechay which is what you want.

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first_letter = word[0]
    second_letter = word[1]

    # check to see if first letter is a vowel    
    if first_letter == ('a' or 'e' or 'i' or 'o' or 'u'): 
        new_word = word + pyg
   
    # check to see if word contains a th, ch, wh     
    elif second_letter == 'h':
        first = word[0:2]
        new_word = word + first + pyg
        new_word = new_word[2:len(new_word)]
    
    # all other cases    
    else:
        first = word[0]
        new_word = word + first + pyg
        new_word = new_word[1:len(new_word)]
        
    print 'here is your translated word:'
    print new_word

else:
    print 'empty'


#2

Why does it matter if it returns gibberish? Pig Latin as a whole was designed to be like a fun game, not to be taken seriously, so it shouldn't matter.


#3

I think that that is the only reason why he made this. Just for fun!


#4

I propose this version that contemplates words that begin with consonant clusters:

pyg = 'ay'
original = raw_input('Enter a word: ')

if len(original) > 0 and original.isalpha():
	word = original.lower()
	first = word[0]
	second = word[1]
  
  # check to see if first letter is a vowel
	if first == 'a' or first == 'e' or first == 'i' or first == 'o' or first == 'u':
		new_word = word + pyg
	
  # check to see if word contains a consonant cluster('smile', 'trash', 'string', 'glove')
	elif second != 'a' and second != 'e' and second != 'i' and second != 'o' and second != 'u':
		new_word = word + first + second + pyg
 		new_word = new_word[2:len(new_word)]
    
  # all other cases
	else:
 		new_word = word + first + pyg
		new_word = new_word[1:len(new_word)]
	print new_word
else:
	print 'empty'