MCS-177 Project 4: Pig Latin Revisited

Start: Thursday 3/6; Due: Monday 3/17, by the beginning of class


Overview

In this project, you will build on your work from the prior project. Instead of just translating individual words between Pig-Latin and English, you will translate entire strings of words. For example, you will translate 'this is Pig Latin' into 'is-thay is-ay ig-Pay atin-Lay' or vice versa. Note, however, that you don't need to properly handle punctuation marks.

You are to do this project individually.

Splitting words apart and joining them back together

In your reading from the textbook (on page 127), a method is introduced for splitting words apart. The textbook also explains how to join a list of words back together into a single string (with spaces in between), but unfortunately this is later in the book, in material you haven't yet been assigned. Therefore, I will show you how to do it now using an example:

          >>> ' '.join(['this', 'is', 'Pig', 'Latin'])
          'this is Pig Latin'

In this example, a string containing just a space character appeared before the dot. This indicates that a space should go between each word and the next. (You could join words together with some other string in between, if you had any reason.)

Specific tasks

  1. Make a copy of piglatin.py you submitted for Project 3 and rename it to piglatin2.py. Open piglatin2.py and work on the following steps.
  2. Write a procedure, unPig, for converting a string consisting of space-separated words from Pig Latin to English. For example, unPig('is-thay is-ay ig-Pay atin-Lay') should return 'this is Pig Latin'. You can use the methods described above for splitting the string of words up into a list and for joining the translated words back together. In particular, don't worry about strings that are fancier than just space-separated words, such as those containing commas. For each individual word you need to translate, use unPigWord. Be sure to consult the list of grading criteria.

  3. Test your unPig procedure and fix it if it doesn't work.

  4. Write an analogous procedure, pig for converting a string of English words into Pig Latin. This ought to be a simple matter of copying, pasting, and making a couple very minor changes. The only reason I'm asking you to do it is to provide a point of comparison when I later teach you a better approach.

  5. Test your pig procedure and fix it if it doesn't work.

Extra credit opportunity

You can earn one or two extra points and gain an appreciation for how convenient the join method is by writing your own procedure for joining together a list of strings. Write a procedure called join such that join(['this', 'is', 'Pig', 'Latin']) returns 'this is Pig Latin'. Your procedure should comply with the following rules:

  1. It should put one space between every pair of consecutive strings from the list.

  2. It should not put any space before the first string or after the last string.

  3. It should work even if given a list containing zero or one strings.

  4. It should not modify the list.

  5. For full credit, it should not be unnecessarily complex.

Submitting your work

You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following file:

Grading

You will earn one point for each of the following accomplishments:

  1. You have a correct contract and docstring for the unPig procedure.

  2. Your unPig procedure correctly splits the string up into a list of words.

  3. Your unPig procedure correctly transforms each word.

  4. Your unPig procedure stores or accumulates the transformed words into some sort of data structure.

  5. Your unPig procedure does the storage or accumulation of transformed words correctly.

  6. Your unPig procedure puts a single space between each two consecutive words.

  7. Your unPig procedure does not add any space at the beginning.

  8. Your unPig procedure does not add any space at the end.

  9. Your unPig procedure works even if given a string of zero words.

  10. Your unPig procedure works even if given a string of one word.

  11. Your unPig procedure returns its result.

  12. Your unPig procedure never uses the same name for two different variables within the same procedure.

  13. Your unPig procedure is not unnecessarily complex.

  14. You provide the testing input and output for unPig.

  15. You have a correct contract and docstring for the pig procedure.

  16. Your pig and unPig procedures differ from one another in all the appropriate ways.

  17. Your pig and unPig procedures do not otherwise differ from one another.

  18. You provide the testing input and output for pig.

  19. You use descriptive names for parameters used in your procedures.

  20. You use descriptive names for variables used in your procedures.

  21. You provide a working join procedure.

  22. Your working join procedure is not unnecessarily complex.