This program is written in Python. Also use correct indentation. Pig Latin is a
ID: 3666284 • Letter: T
Question
This program is written in Python. Also use correct indentation.
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.
• 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. 5
• 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.
• 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
Goodbye!
Explanation / Answer
phrase = 'This phrase will be converted into piglatin, please insert your phrase here.'
pigString= 'is-Thay ig-Pay atin-Lay ase-phray ill-way e-bay anslated-tray ack-bay o-intay e-thay ative-nay anguage-lay -asay -aay ing.-stray'
def unpigPhrase (phrase):
sentence = phrase.split()
unpiggedphrase = []
for word in sentence:
unpiggedphrase.append(unpigword(word))
return ' '.join(unpiggedphrase)
def pigPhrase (phrase):
sentence = phrase.split()
piggedphrase = []
for word in sentence:
piggedphrase.append(pigword(word))
return ' '.join(piggedphrase)
def unpigword (piggedword):
return piggedword[(piggedword.find('-') +1):-2] + piggedword[0:piggedword.find('-')]
def findvowel (word):
vowels = "aeiouAEIOU"
for i in range (0,len(vowels)):
vowelnumber = word.find(vowels[i])
if vowelnumber > 0:
return vowelnumber
else:
if i == len(vowels)-1:
return len(word)
def pigword (word):
return word[findvowel(word):] + "-" + word[:findvowel(word)] + "ay"
def join (List):
if List == []:
return ''
else:
sentence = List[0]
for word in range (1, len(List)):
sentence = sentence + ' ' + List[word]
return sentence
print pigPhrase(phrase)
print unpigPhrase(pigString)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.