Advertisement
e_mccormick

6.189 Homework 2, OPT.1 - Pig Latin Sentences

Jun 20th, 2013
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. # 6.189 Homework 2.9 - Pig Latin Funtion
  2. # 6.189 Homework 2, OPT.1 - Pig Latin Sentences
  3.  
  4. def pig_latin(word):
  5.     """Converts a word into Pig Latin and returns it.
  6.    This would be so much cleaner with a Regular Expression!"""
  7.     first_letter = word[0].lower()
  8.     two_let = ''
  9.     punctuation=''
  10.     if word[-1]=="!" or word[-1]=="." or word[-1]=="," or word[-1]=='"' or word[-1]=="'" or word[-1]=="?":
  11.         punctuation=word[-1]
  12.         word=word[:-1]
  13.     if first_letter == 'a' or first_letter == 'e' or first_letter == 'i' or first_letter == 'o' or first_letter == 'u':
  14.         return word+"hay"+punctuation
  15.     else:
  16.         try:
  17.             two_let=word[0:2].lower()
  18.         except:
  19.             two_let=''
  20.         if two_let=='th' or two_let=='st' or two_let=='qu' or two_let=='pl' or two_let=='tr':
  21.             return word[2:]+first_letter+word[1]+'ay'+punctuation
  22.         else:
  23.             return word[1:]+first_letter+'ay'+punctuation
  24.  
  25.  
  26.  
  27. line_in = input('What do you wish to Pig? ')
  28. line_out = ''
  29. for word in line_in.split():
  30.     line_out = line_out + ' ' + pig_latin(word)
  31.  
  32. print(line_out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement