In: Computer Science
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. Remembertranslatemusttakeonlyonewordasinput.
############################################################# # 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
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))