Question
Part 2: Pig Latin Translator (15 points) Complete the function `translate_word`, which returns the Pig Latin translation of the provided word, given as the parameter
Part 2: Pig Latin Translator (15 points)
Complete the function `translate_word`, which returns the Pig Latin "translation" of the provided word, given as the parameter `word`. The rules of Pig Latin are:
* If a word starts with a consonant and a vowel, put the first letter of the word at the end of the word and add "ay." * Example: happy = appyh + ay = appyhay
* If a word starts with two consonants, move the two consonants to the end of the word and add "ay." * Example: child = ildch + ay = ildchay
* If a word starts with a vowel, add the word "way" at the end of the word. * Example: awesome = awesome + way = awesomeway
Before performing any translations, change the input word into all lowercase. You may assume that the input word contains only letters.
Hint #1: use slicing and concatenation to carve up the word and rearrange the letters as needed.
Hint #2: use nested if-statements to check if a word begins with a consonant or vowel and then, in the case where the word starts with a consonant, have an inner if-statement check if the next letter is a consonant or vowel. To get you started, two variables have been created for you:
` vowels = 'aeiou' consonants = 'bcdfghjklmnpqrstvwxyz' ```
The idea here is that you can use the `in` operator to check whether a particular letter in the input `word` argument is a consonant or vowel. As an example:
``` if word[0] in consonants ```
Now, to test your work, a completed function named `translate_sentence` has been provided to see if your own `translate_word` function works properly.
Example:
* `print(translate_sentence('To be or not to be that is the question.'))` * Output: `otay ebay orway otnay otay ebay atthay isway ethay uestionqay`
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started