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:
English | Pig Latin |
---|---|
this | is-thay |
is | is-ay |
Pig | ig-Pay |
Latin | atin-Lay |
shh | -shhay |
she | e-shay |
You may work with a partner for pair programming.
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.
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.
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.
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:
You will earn one point for each of the following accomplishments:
unPigWord
procedure.Your unPigWord
procedure correctly locates the hyphen.
In locating the hyphen, you make good use of Python's string-handling features, avoiding excess complexity.
Your unPigWord
procedure correctly extracts the substring preceding the hyphen.
Your unPigWord
procedure correctly extracts the substring between the hyphen and the ending.
In extracting the substring preceding and succeeding the hyphen, you make good use of Python's string-handling features, avoiding excess complexity.
Your unPigWord
procedure correctly forms its return value from the identified substrings.
findVowel
procedure.Your findVowel
procedure uses the given definition of what a "vowel" is.
Your findVowel
procedure correctly finds the first vowel within the string.
Your findVowel
procedure makes good use of Python's string-handling features to avoid excess complexity.
Your findVowel
procedure returns the specified value when given a string with no vowel.
pigWord
procedure.Your pigWord
procedure appropriate finds the dividing position within the given string.
Your pigWord
procedure correctly extracts the substring prior to the dividing position.
In extracting the substring prior to the dividing position, you make good use of Python's string-handling features, avoiding excess complexity.
Your pigWord
procedure correctly extracts the substring starting at the dividing position.
In extracting the substring starting at the dividing position, you make good use of Python's string-handling features, avoiding excess complexity.
Your pigWord
procedure correctly forms its return value.
All names within your procedures are descriptive.