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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!