www.cs.amherst/~ccm/cs111/prog1.html

Second Programming Assignment

This assignment is due by 5pm Friday, November 1st. Your mission is to write a Python program that reads in an English text and converts it to Pig Latin. For example, if you type in the text:
Now is the time for all good men to come to the aid
of their country.  The quick brown fox jumps over the
lazy dog.  Yes, I got rhythm. 
The program should print out:
Ownay isway ethay imetay orfay allway oodgay enmay otay ometay otay ethay aidway 
ofway eirthay ountrycay. Ethay ickquay ownbray oxfay umpsjay overway ethay 
azylay ogday.  Esyay, Iway otgay ythmrhay. 
Your translater should match the capitalization, punctuation, and use of whitespace (including spaces, tabs and newlines) of the original, as shown above.

(As an alternative, if you know Openglopish: Yopou copan tropanslopate thopat opinstopead.)

Rules of Pig Latin

Pig Latin is a fake language beloved by English-speaking children around the world (as far as I know). It uses the same grammer as English, but individual words are translated as follows:

  1. If a word begins with a consonant or a series of consonants, the consonants are moved to the end of the word, and "ay" is attached, like this:

  2. If the word begins with a vowel, the word stays intact, and ``way'' is added to the end, like this:

  3. If a word starts with y, the y is treated as a consonant. Otherwise y is considered to be a vowel. If a word starts with qu, both letters are considered consonants.

Free advice

Your best strategy here is to break the problem down into component parts and write the individual functions. Get a little part of it working before moving on to the next part: Start by building a function that takes a single word (no spaces) and converts it to Pig Latin. Then build some kind of loop to find single words (separated by single spaces) in a string of words. Then figure out how to skip punctuation marks and such to find the single words in a more complicated text. Wait to the end to worry about getting the upper/lower cases and the newlines correct.

Turning it In

  1. Name your file piglatin.py.
  2. Demonstrate your Pig Latin program by running it on a text string that I will give you closer to the time. Turn in both the code for your program and the trace file showing how it works.