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:
isalphasays they are. (This includes the 26 uppercase and 26 lowercase letters in the English alphabet).
a e i o uand their uppercase variants, but never
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)
Helloand the non-letter
my_stringcontains nothing but letters. (Note that
my_stringcould be a single character.)
" -- ",
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.
def piggify_word(word): return word
chis a vowel,
Falseif it isn't.
cut("String")should return the tuple
' ') to separate the sentence into a list of word-like chunks ("raw" words), and returns that list of chunks. For example,
("Madam, I'm Adam.")should return the list
["Madam,", "I'm", "Adam."].
(word, punctuation)pairs and returns the corresponding list of
("piggified" word, punctuation)pairs. For example,
piggify_pairs([("hi", ""), ("there", "!")])should return
[("ihay", ""), ("erethay", "!")].
(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
mainmethod) 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:
Here's what this does. If you are in the IDLE window containing your program, and you click
if __name__ == "__main__": main()
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
F5or 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.