Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago