MCS-177 Project 3: Pig Latin

Start: Tuesday 9/23; Due: Monday 9/30, by the beginning of class


Overview

Sometimes when adults don't want small children to understand what they are saying, they disguise each of the English words they are speaking by transforming it into a corresponding "Pig Latin" word. There are many different variants of Pig Latin in use, so if you think you already know Pig Latin, you should still pay careful attention to the specific rules given in this assignment; they may be a bit different from the ones you know. Also, because Pig Latin is fundamentally a spoken language and the connection between English spelling and pronunciation is so weird, no simple set of rules can possibly get all cases right. Just follow the rules I state and don't worry if their behavior on some weird cases seems wrong. You will be writing procedures for translating individual words from Pig Latin to English and from English to Pig Latin. The following table gives some examples. One of your procedures will translate a word from the right-hand column into the corresponding word on the left; your other procedure will do the reverse:

EnglishPig Latin
thisis-thay
isis-ay
Pigig-Pay
Latinatin-Lay
shh-shhay
shee-shay

You may work with a partner for pair programming.

Specific tasks

  1. Write a procedure called unPigWord. The procedure should have one parameter, the Pig Latin word that should be translated to English. You may assume that every time your procedure is used, it is passed a string that has exactly one hyphen ("-") in it and ends with the letters "ay". Your procedure should start by finding the position of the hyphen. Your procedure should then extract from the string two substrings: the portion before the hyphen and the portion between the hyphen and the "ay" ending. For example, when given the string "is-thay", the two substrings are "is" and "th". Finally, your procedure should combine these two substrings in the reverse order and return the result. In the preceding example, this would be "this". Make sure your procedure works on the examples from the earlier table and is not unnecessarily complex.

  2. Write a procedure called findVowel that takes a single parameter, a string, and finds the first position within that string where any of the characters "aeiouAEIOU" appears. For example, given the string "is", your procedure should return 0, and given the string "Pig", your procedure should return 1. If the string doesn't have any of the listed vowels in it at all, such as with the string "shh", then your procedure should return the length of the string, which would be 3 in this example. Make sure your procedure works correctly and is not unnecessarily complex.

  3. Write a procedure, pigWord, which returns the translation of a single word from English to Pig Latin. The translation consists of everything from the first vowel onward (as determined by findVowel), then a hyphen, the portion of the word that preceded the first vowel, and the letters "ay". Make sure your procedure works on the examples from the earlier table and is not 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 written a correct contract/docstring for the unPigWord procedure.
  2. Your unPigWord procedure correctly locates the hyphen.

  3. In locating the hyphen, you make good use of Python's string-handling features, avoiding excess complexity.

  4. Your unPigWord procedure correctly extracts the substring preceding the hyphen.

  5. Your unPigWord procedure correctly extracts the substring between the hyphen and the ending.

  6. In extracting the substring preceding and succeeding the hyphen, you make good use of Python's string-handling features, avoiding excess complexity.

  7. Your unPigWord procedure correctly forms its return value from the identified substrings.

  8. You have written a correct contract/docstring for the findVowel procedure.
  9. Your findVowel procedure uses the given definition of what a "vowel" is.

  10. Your findVowel procedure correctly finds the first vowel within the string.

  11. Your findVowel procedure makes good use of Python's string-handling features to avoid excess complexity.

  12. Your findVowel procedure returns the specified value when given a string with no vowel.

  13. You have written a correct contract/docstring for the pigWord procedure.
  14. Your pigWord procedure appropriate finds the dividing position within the given string.

  15. Your pigWord procedure correctly extracts the substring prior to the dividing position.

  16. In extracting the substring prior to the dividing position, you make good use of Python's string-handling features, avoiding excess complexity.

  17. Your pigWord procedure correctly extracts the substring starting at the dividing position.

  18. In extracting the substring starting at the dividing position, you make good use of Python's string-handling features, avoiding excess complexity.

  19. Your pigWord procedure correctly forms its return value.

  20. All names within your procedures are descriptive.