Please use Python to do the coding! Write a program that takes a 3 word phrase a
ID: 3789795 • Letter: P
Question
Please use Python to do the coding!
Write a program that takes a 3 word phrase and then converts the words to Pig Latin.
To review, Pig Latin takes the rst letter of a word, puts it at the end, and appends “ay”. The only exception is if the rst letter is a vowel, in which case we keep it as it is and append “hay” to the end.
E.g. “boot” “ootbay”, and “image” “imagehay”.
There are many more Pig Latin rules, but for this homework this is sufficient.
Dene a GLOBAL list at the top of your code le called VOWELS. This way, you can check if a letter x is a vowel with the expression x in VOWELS. Remember to get a word except for the rst letter, you can use word[1:].
It’s tricky for us to deal with punctuation and numbers with what we know so far, so instead, ask the user to enter only 3 words and spaces. You need to convert their input from a string to a list. Also convert the 3 word phrase to all lower when doing comparisons against the vowels list.
Using a list of words, you can go through each word and convert it to Pig Latin by calling the function ConvertWordToPigLatin. Make sure you have a check in your code that it only converts lists that are of length 3 to Pig Latin.
Break all the tasks into functions. Should have functions that: reads user input with name AskUserForSentence, lowercases the sentence called LowercaseSentence, splits the phrase called SplitSentenceIntoList, converts the word to pig latin called ConvertWordToPigLatin and prints out the 3 word phrase in pig latin called PrintThreeWordPhrase. Remember, using functions makes your code much more re-usable, readable and clean.
Once you have your program working, make it interactive such that it keeps translating 3 word phrases into pig latin until the user enters in the phrase QUIT.
Explanation / Answer
ph = input("Enter a phrase: ")
ph = ph.split()
dt=[]
for l in ph:
if l[0] in ['a','e','i','o','u']:
l = l+"hay"
else:
l = l[1:]+l[0]+"ay"
dt.append(l)
print(" ".join(dt))