Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Pig Latin is a simple transformation of English text. Each word of the text is converted as follows: move any consonant (or consonant cluster) that
Pig Latin is a simple transformation of English text. Each word of the text is converted as follows: move any consonant (or consonant cluster) that appears at the start of the word to the end, then append 'ay': e.g. 'string' becomes lingstray', 'idle' becomes lidleay', 'horse' becomes 'orsehay', and so on. The program shown below takes a word and converts it to Pig Latin. In [1]: # Pig Latin is a simple transformation of English text. # Each word of the text is converted as follows: * move any consonant (or consonant cluster) that appears # at the start of the word to the end, then append 'ay', e.g. # 'idle' becomes 'idleay', 'horse' becomes 'orsehay', # stove' becomes 'ovestay', 'string' becomes 'ingstray'. def pig_latin(string): vowels = ['a', 'o', 'i', 'e', 'u'] if string(0) in vowels: # if the first letter is vowel return string + 'ay' elif string[1] in vowels: # if the first letter is consonant return string(1:) + string[0] + 'ay' elif string[2] in vowels: # if the first two letters are consonants return string(2:] + string[:2] + 'ay' else: # if the first three letters are consonants return string(3:] + string[:3] + 'ay' Task: Modify the program below so that it converts text, instead of individual words. Your new program should accept the string 'the empire strikes back' and to output the string translated into Pig Latin: 'ethay empireay ikesstray ackbay'
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