Question

In: Computer Science

Create a program that translates English into Pig Latin. The function will take the first letter...

Create a program that translates English into Pig Latin.

The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”.

Your program must be case ​ins​ ensitive. You must write the functiontranslate() ​that takes in a single English word and ​returns​ its Pig Latin translation. Remembertranslatemusttake​onlyonewordasinput.​

#############################################################
# translate() takes a single english word translates it to
#pig latin
# Input:english_word; an English word
# Output:the pig latin translation

Here is some sample output, with the user input in ​blue​.
(Yours does not have to match this word for word, but it should be similar.)

linux[0]$ python hw5_part4.py
Enter an English phrase: ​You look nice today
I think you meant to say: Youay ooklay icenay odaytay

Enter an English phrase: ​Again we don't have to worry about punctuation.
I think you meant to say: Againay eway on'tday avehay otay orryway aboutay unctuation.pay

Enter an English phrase: ​I realized that this problem isn't as easy as I had thought.
I think you meant to say: Iay ealizedray hattay histay roblempay isn'tay asay easyay asay Iay adhay hought.tay

Enter an English phrase: ​Owls have 14 vertebrae in their necks. So fancy!
I think you meant to say: Owlsay avehay 41ay ertebraevay inay heirtay ecks.nay oSay ancy!fay

Solutions

Expert Solution

CODE

#############################################################

# translate() takes a single english word translates it to

#pig latin

# Input:english_word; an English word

# Output:the pig latin translation

def translate(words):

pyg = 'ay'

words = words.split(" ")

result = ""

for word in words:

if len(word) > 0:

word_temp = word.lower()

first = word_temp[0]

if first == ('a' or 'e' or 'i' or 'o' or 'u'):

new_word = word + pyg

else:

new_word = word[1:] + first + pyg

result += new_word + " "

return result

sentence = input("Enter an English phrase: ​")

print("I think you meant to say: " + translate(sentence))


Related Solutions

C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console...
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console Pig Latin Translator This program translates a sentence and removes all punctuation from it. Enter a sentence: 'Tis but a scratch. Translation:      Istay utbay away atchscray Specifications Convert the English to lowercase before translating. Remove all punctuation characters before translating. Assume that words are separated from each other by a single space. If the word starts with a vowel, just add way to the...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin that doesn't allow follow all the Pig Latin Syntax rules.) Use predefined methods of the Array and String classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters "ay" onto the end. For example, the word "example" would become "xampleay" and "method" would become "ethodmay." Allow the user to...
How do I write a COBOL program that translates a word entered into pig Latin?
How do I write a COBOL program that translates a word entered into pig Latin?
Use python write a function that translates the input string into Pig Latin. The translation should...
Use python write a function that translates the input string into Pig Latin. The translation should be done word by word, where all words will be separated by only one space. You may assume that each word must have at least one vowel (a,e,i,o,u and uppercased counterparts), and there will be no punctuation or other special characters in the input string. The Pig Latin rules are as follows: For words that begin with consonants, all letters before the initial vowel...
python Create a dictionary and insert several English words as keys and the Pig Latin (or...
python Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values. Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%. Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish and Spanish to English. Your translation program should use arrays for this program. You will need to populate the arrays with the contents of the English and Spanish data files provided. The two files are ordered such that each word in the one file corresponds to the respective translation in the other (i.e.: the first word in the ENG.txt file corresponds to the first...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which words in English are altered, usually by removing letters from the beginning of a word and arranging them into a suffix. The rules we will use for the pig-latin in this program are as follows: If a word starts with a consonant, split the word at the first instance of a vowel, moving the beginning consonants to the end of the word, following a...
Pig Latin is a language constructed by transforming English words. The following rules are used to...
Pig Latin is a language constructed by transforming English words. The following rules are used to translate English into Pig Latin: *If the word begins with a consonant, then all consonants at the beginning of the word, up to the first vowel are removed then added to the end of the word, followed by “ay”. For example, “computer” becomes “omputercay” and “think” becomes “inkthay”. *If the word begins with a vowel, then “way” is added to the end of the...
Write a program that translates a letter grade into a number grade. Letter grades are A,...
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or F-. A “+” increases the numeric value by 0.3, a “–“ decreases it by 0.3. However, an A+ has value 4.0.4 pts Enter a Letter grade: B- The numeric value is 2.7 Your code with comments A screenshot...
question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules:...
question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules: For every word in a sentence, the firstletter of the word is shifted to the end of the word and the suffix “-ay” is added at the end of the word. For example, “hey pat”becomes “eyhay atpay”.Implement thepiglatin(str)function so it translates sentences to pig latin. If you have time remaining, try implementing afunction to ”decrypt” piglatin, i.e. given a sentence in piglatin, return the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT