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...
How would you go about writing a MATLAB program to convert a phrase in Pig Latin...
How would you go about writing a MATLAB program to convert a phrase in Pig Latin to English. I have already written a script that converts phrases from English into Pig Latin; however, I am not sure how to reverse the process. Can anyone who know's MATLAB please help me out, thank you? P.S. I know that this is an unambigious task so it doesn't have to work completely well. With the most minor assumptions made, if it could covert...
Write a program to take input of scores for Chemistry, Biology and English for a student...
Write a program to take input of scores for Chemistry, Biology and English for a student and display the average with 2 decimal places if all of the three scores are in the range between 1 and 100 inclusive. Program should also display the course name for which scores are entered out of range telling Average couldn't be calculated. Following is a sample run: Enter scores for Chemistry, Biology and English between 1 and 100: 45 89 96 Avg score...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT