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
that you don't need to handle punctuation marks.
You are to do this project individually.
The string method split
(see the textbook page 127)
will be very useful in this project.
Write a procedure, joinWords
, for
joining a list of words into a single string, where every two consecutive words are separated by a given separator string.
It should take in two parameters, a list of strings and a separator (which is a string object). It returns a string of the words separated by the separator string.
It should put the given separator string between every pair of consecutive strings from the list.
It should not put any separator string before the first string or after the last string.
It should work even if the given list is empty or contains only one item.
It should not modify the list. For example, do not use the list methods pop
or append
.
You should use descriptive names for parameters and variables.
You must use accumulator pattern (a for loop and string concatenation) to implement this function.
Include the contract and docstring for joinWords
.
Don't worry about treating punctuation marks or commas or other special characters.
You may want to look back to the procedure IntegerBars
which you wrote for Project 2.
Finally, be sure to consult the grading rubric.
Test your joinWords
procedure and fix it if it doesn't work. The following are a few examples:
>>> joinWords(['this', 'is', 'Pig', 'Latin'], ' ') 'this is Pig Latin' >>> joinWords(['Latin'], '!') 'Latin' >>> joinWords([], '!') '' >>> joinWords(["I", "like", "Python"], "???") 'I???like???Python' >>> joinWords(["Accumulator", "pattern", "is", "the", "best"], "++") 'Accumulator++pattern++is++the++best' >>> joinWords(['1', '22', '500'], '|') '1|22|500' >>> joinWords(['1', '22', '500'], '') '122500'
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'
.
split
(described in the textbook on page 127) for splitting the string of words up into a list.
joinWords
you wrote for joining the translated words back together.
unPigWord
function you wrote for Project 3.
unPig
.Don't worry about strings that are fancier than just space-separated words, such as those containing commas. Be sure to consult the grading rubric.
Test your unPig
procedure and fix it if it doesn't work. The following are a few examples:
>>> unPig('is-Thay is-ay e-shay') 'This is she' >>> unPig('is-thay is-ay ig-Pay atin-Lay') 'this is Pig Latin' >>> unPig("ig-Pay atin-Lay") 'Pig Latin' >>> unPig("-Shhay ou-yay") 'Shh you' >>> unPig('atin-Lay') 'Latin' >>> unPig('') ''
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. You should copy and paste your
pigWord
and findVowel
functions
from
Project 3. You should use descriptive names for parameters and variables in your procedure.
Test your pig
procedure and fix it if it doesn't work.
Submit your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit one Python file called
joinWords
, unPig
and pig
which you wrote.
Be sure to include all other procedures called by your functions above (for example, if your functions call unPigWord
, findVowel
, and pigWord
), then you have to include these as well, otherwise your functions would not work.
The grader will test your program against various input values. Check your work against the grading rubric project4gradesheet.pdf which the grader will use when grading your lab.