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.
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.)
piglatin.py
you submitted for Project 3 and rename it to piglatin2.py
. Open piglatin2.py
and work on the following steps.
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.
Test your unPig
procedure and fix it if it doesn't work.
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.
Test your pig
procedure and fix it if it doesn't work.
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:
It should put one space between every pair of consecutive strings from the list.
It should not put any space before the first string or after the last string.
It should work even if given a list containing zero or one strings.
It should not modify the list.
For full credit, it should not be 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:
unPig
and pig
procedures. You will earn one point for each of the following accomplishments:
You have a correct contract and docstring for the unPig
procedure.
Your unPig
procedure correctly splits the string up into a list of words.
Your unPig
procedure correctly transforms each word.
Your unPig
procedure stores or accumulates the transformed words into some sort of data structure.
Your unPig
procedure does the storage or accumulation of transformed words correctly.
Your unPig
procedure puts a single space between each two consecutive words.
Your unPig
procedure does not add any space at the beginning.
Your unPig
procedure does not add any space at the end.
Your unPig
procedure works even if given a string of zero words.
Your unPig
procedure works even if given a string of one word.
Your unPig
procedure returns its result.
Your unPig
procedure never uses the same name for two different variables within the same procedure.
Your unPig
procedure is not unnecessarily complex.
You provide the testing input and output for unPig
.
You have a correct contract and docstring for the pig
procedure.
Your pig
and unPig
procedures differ from one another in all the appropriate ways.
Your pig
and unPig
procedures do not otherwise differ from one another.
You provide the testing input and output for pig
.
You use descriptive names for parameters used in your procedures.
You use descriptive names for variables used in your procedures.
You provide a working join
procedure.
Your working join
procedure is not unnecessarily complex.