PA07
A Pig Latin Translater
Objective:
Get more practice with strings, looping, and writing functions
Code due by Friday, April 3rd, at 11:59pm
An introduction
You are contacted by Mr. I. Hoggs, president of the IPLS (International Pig
Latin Society). He admits that despite being president of the society, he
has always had some difficulty converting from English to Pig Latin. He asks if you could
help him by writing a program to convert words/sentences from English to traditional "Pig Latin."
Pig Latin?
Some of you may have played with Pig Latin as a kid. There are many
slightly different rule sets for Pig
Latin. The version we will use is:
- RULE 1 - If the word begins with a consonant - such as "hello" or "this" - divide
the word at the first vowel, swapping the front and back parts of the word and
append "ay" to the word. The previous 2 examples would produce "ellohay" and "isthay".
- RULE 2 - If the word begins with a vowel - such as "am", "are" or "i" - append "way"
to the word. The previous examples would produce "amway", "areway" and "iway".
- RULE 3 - If the word has no vowels - such as "my" or "thy" - leave them alone.
The examples would produce "my" and "thy".
The Final Project
I want your code to take
in a single sentence (with no punctuation except the ending period) and
translate that sentence into pig latin.
Let's think about this problem
from the top down. Our full blown project should:
- Read a single "sentence" from the user.
- Break the sentence into individual words
- For each word, convert it into PigLatin...
- by finding the first vowel (if it exists)
- And finally, print out these converted words in normal sentence format
As we look at this project, we want to do this in several manageable steps
(incremental development).
Part A - Finding the first vowel
Begin by writing a function (in a file called pa07.py) called findFirstVowel(). This function should
- Take in a single parameter which is assumed to be a single word
- Search that word for the index location of the first vowel ('a', 'e', 'i', 'o', 'u').
- It then returns the index value of that first vowel, or a negative
1 when there is no vowel.
- Make sure that this function works regardless of the case of the letters
submitted
For example,
Part B - Translating one word
Now, write another function called translateWord() that:
- Takes in a single parameter which is assumed to be a single word
- Sends that word to findFirstVowel() (from Part A) and grabs the
result sent back
- It uses the result
of part A to see which of the three rules apply (see above)
- It uses this
information to modify the word appropriately, and returns the String representing the translated word.
For example,
Part C - Starting to translate one sentence
This turns out to have several pieces to it, so let's break it down into sub
steps
Now add a function to your code called pigLatinTranslator(). This function
should:
- Accept a single parameter, assumed to be one sentence.
- You may assume there are no punctuation marks IN it (no commas, no
hyphens, etc.).
- You should assume that there is a period at the end of the sentence
- Removes the period from the sentence and changes all to lowercase letters
- Breaks the sentence into individual words using split().
- Uses the translateWord() function from part B to translate each word.
You should put these translated words back together into a single sentence string. Once you have done that, your function should:
- Capitalize the first letter.
- Put the period back on the end.
- RETURN the final output string (sentence)
For example,
Final Submission
Please submit your pa07.py file to the autolab Program Submission System. It will be grading your code by running each function individually. This means you will get some points for getting the first function to work, some points for getting the second function to work, and some more points for getting the last function to work. However, please don't just submit things to the grading system before testing them on your end. It would be a good idea for you to write a testing suite like we used in lab 8 to test your own function to make sure they work.
Don't forget to fill in your function comments!