In this assignment you will write a program to translate English sentences into "Pig Latin."
Pig Latin is a "secret" language used by children, often in the belief that their parents won't understand them. The rules are simple:
isalpha
says they are. (This includes the 26 uppercase and 26 lowercase letters
in the English alphabet).a e i o u
and their uppercase variants, but never y or w.sentence.split(' ') will give return a list of
strings, but some of those strings will be the empty string, and
those you need to get rid of."Hello," consists of the word
(by our rules) Hello and the non-letter ,
(comma).my_string.isalpha() will return True
if my_string contains nothing but letters. (Note that
my_string could be a single character.)"--Dave""$500",
" -- ", "cwm"def piggify_word(word):
return word
Now write the test. It should fail (if it doesn't, already there's
something wrong). Then write the code, test it, and debug until it works.
Once it's working, refactor it--clean up
any little things that could be done better--and make sure it still works.pig_latin.py and pig_latin_test.py.def is_vowel(ch)True if ch is a vowel, False
if it isn't.def cut(word)cut("String")
should return the tuple ("Str", "ing").def piggify_word(word)cut
function.)def clean_word(raw_word)clean_word("Wow!") should
return ("Wow", "!").def get_raw_words(sentence)' ') to separate the sentence
into a list of word-like chunks ("raw" words), and returns that list of
chunks. For example, get_raw_words("Madam, I'm
Adam.") should return the list ["Madam,", "I'm",
"Adam."].def piggify_pairs(pair_list)(word, punctuation)
pairs and returns the corresponding list of ("piggified" word,
punctuation) pairs. For example, piggify_pairs([("hi",
""), ("there", "!")]) should return [("ihay", ""),
("erethay", "!")].def reassemble(pair_list)(word, punctuation)
pairs into a sentence. The word and its associated punctuation are
concatenated, and the words are assembled into a sentence, with spaces
between words (but no space at the beginning or at the end). For
example, reassemble([("ihay", ""), ("erethay", "!")])
should return "ihay erethay!".def piggify_sentence(sentence)def main()main method) when the
user enters a blank line. This is the only function that does
input/output, and is the only function that does not require
a unit test.At the end of your Python program (after all your function definitions), insert the following lines:
if __name__ == "__main__":
main()
Here's what this does. If you are in the IDLE window containing your
program, and you click F5 (or choose Run -> Run
module) from the menu, IDLE will automatically run your main
function. If you are in the IDLE window containing your test cases
(supplied) and click F5 or use the menu equivalent, it will
run the tests and tell you the results.Zip your two Python files and turn them in to Canvas by 6am Wednesday, September 9.