Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

pyglatin.py

By: musicguyguy on Jun 15th, 2013  |  syntax: Python  |  size: 3.71 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. print "Welcome to the English to Pig Latin Translator!"
  2.  
  3. import sys
  4.  
  5. pyg = "ay"
  6.  
  7. vowel = "a","e","i","o","u"
  8. v_sound = "hour","heir","honor","honest"                                         # complete???
  9.  
  10. consonant = "b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"
  11. c_four = "chth","phth","schl","schm","schn","schr","scht","schw","sphr"
  12. c_three = "chr","chl","cht","ngw","phl","phr","psh","sch","scl","scr","sgr","shk","shl","shm","shn","shr","sht","sph","spl","spr","sth","str","tch","thr","thw","tsk"
  13. c_two = "ch"
  14. c_sound = "uni"                                                                  # complete???
  15.  
  16. def PygLatin():
  17.     def Translate():
  18.         c_message = "Your entry %s begins with a consonant sound, so the consonant sound with appended \"-%s\" will be moved to the end. Translated to Pig Latin, your entry is:" %(word,pyg)
  19.         confirm = raw_input(word+"\nIs this the word you entered?[Y/N] ")
  20.         if confirm in ["y","yes"] :
  21.             if word.startswith(vowel) or word.startswith(v_sound) :              # Begins with a vowel or vowel sound
  22.                 print "Your entry \"%s\" begins with a vowel sound, so \"-%s\" will simply be appended at the end. Translated to Pig Latin, your entry is:" %(word,pyg)
  23.                 pig = "%s-%s" %(word,pyg)
  24.                 print pig
  25.                 TryAgain()
  26. #            elif len(word) > 100 :                                               # Entirely consonants???
  27. #                print "Your entry \"%s\" is entirely consonants, so \"-%s\" will simply be appended at the end. Translated to Pig Latin, your entry is:" %(word,pyg)
  28. #                print "%s-%s" %(word,pyg)
  29. #                TryAgain()
  30.             elif word.startswith(c_four) :                                       # Begins with four consonants
  31.                 print c_message
  32.                 pig = "%s-%s%s" %(word[4:],word[0:4],pyg)
  33.                 print pig
  34.                 TryAgain()
  35.             elif word.startswith(c_three) :                                      # Begins with three consonants
  36.                 print c_message
  37.                 pig = "%s-%s%s" %(word[3:],word[0:3],pyg)
  38.                 print pig
  39.                 TryAgain()
  40.             elif word.startswith(c_two) :                                        # Begins with two consonants
  41.                 print c_message
  42.                 pig = "%s-%s%s" %(word[2:],word[0:2],pyg)
  43.                 print pig
  44.                 TryAgain()
  45.             elif word.startswith(consonant) or word.startswith(c_sound) :        # Begins with a consonant or consonant sound
  46.                 print c_message
  47.                 pig = "%s-%s%s" %(word[1:],word[0],pyg)
  48.                 print pig
  49.                 TryAgain()
  50.             else:                                                                
  51.                 print "Either your entry is not English or the Pig Latin Translator has not yet figured out how to translate your word. Sorry!"
  52.                 TryAgain()
  53.         if confirm in ["n","no"]:
  54.             TryAgain()
  55.         else:
  56.             Translate()
  57.  
  58.     word = raw_input("Enter an English word to be translated to Pig Latin: ").lower()
  59.     if len(word) > 0 and word.isalpha():
  60.         Translate()
  61.     elif word.isalpha() :
  62.         print "There was something wrong with your entry. Try again using only alphabetic characters."
  63.         TryAgain()
  64.     else:
  65.         PygLatin()
  66.  
  67. def TryAgain():
  68.     repeat = raw_input("\nStart over?[Y/N] ").lower()
  69.     if repeat in ["y","yes"] :
  70.         print "OK.\n"
  71.         PygLatin()
  72.     elif repeat in ["n","no"] :
  73.         raw_input("\nPress ENTER to exit the English to Pig Latin Translator.")
  74.         sys.exit()
  75.     else:
  76.         TryAgain()
  77.  
  78. PygLatin()