Question
These programs need to be written in Python Pig Latin is a form of coded English often used for amusement. There are many variations on
These programs need to be written in Python
Pig Latin is a form of coded English often used for amusement. There are many variations on the method used to form pig Latin sentences. Here, we use the following simple algorithm to translate an English word into pig Latin:
If the English word begins with a consonant, place the initial cluster of consonant letters at the end of the word, followed by the letters ay to it. For example, road translates to oadray, scream translates to eamscray, and fly translates to flyay.
If the English word begins with a vowel (a vowel is one of a,e,i,o, or u), simply add the letters way at the end of the word. For example, apple translates to appleway and I translates to Iway.
Write a program that translates English language sentences into pig Latin. We will assume that the sentence is made up of words separated by blanks. A word is a string of letters without blanks and may end in a punctuation mark, which we assume to be one of . (period) ! (exclamation) ? (question mark) or , (comma). We assume there are no other punctuation marks in the sentence. The punctuation marks and blanks stay as they are in the pig Latin translation. Implement the following functions in your program.
1. Write a function called pig_latin_word with a single parameter word. Assume that word is a string of characters without any spaces or punctuation marks in it. The function returns a string that is the pig Latin translation of word.
2. Write a function called pig_latin_sentence with a single parameter eng_sentence, which is an English language sentence. The function returns a string which is the pig Latin translation of eng_sentence. Hint: Construct the pig Latin translation by breaking up eng sentence into words, each of which can be translated using pig latin word. Make sure you handle punctuation marks properly
3. Write a function called pig_latin_translator without any parameters. The function repeatedly reads in an English sentence from the user and then uses the function pig_latin_sentence to print out the pig Latin translation of that sentence.
Here is a sample run:
------------------------------- English to Pig Latin Translator -------------------------------
Enter the English sentence: Look! His tie is ugly.
In Pig Latin: ookLay! isHay ietay isway uglyway.
Do another? [y/n] y
Enter the English sentence: Are you speaking Pig Latin?
In Pig Latin: Areway ouyay eakingspay igPay atinLay?
Do another? [y/n] n
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