Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Based on the following code, write a function called pl_translate that properly

ID: 664197 • Letter: B

Question

Based on the following code, write a function called pl_translate that properly handles adding the ay and yay word endings, capital letters, and punctuation. This task is to be done in Python.

#definition of pl_prefix function
def pl_prefix(word):
     #create vowel set
     vowels = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U")
     newString=""

     #use for loop to get prefix from user
     for i in range(len(word)):
          if word[i] in vowels:
               break
          else:
               newString=newString + word[i]

     #return the prefix
     return newString      

#definition of pl_reverse function
def pl_reverse(word):
     # call the pl_prefix function by passing the word
     # and get the prefix value
     prefix = pl_prefix(word)

     # get the stem of the word
     stem = word[len(prefix):len(word)]

     # reverse the stem
     reverse = stem[::-1]

     # add the prefix the prefix value to the reverse value
     newWord = prefix + reverse

     # return the obtained result  
     return newWord


# prompt the user to enter the word
inputword = raw_input("Please enter a word: ")

# get the pilatin word by calling the pl_prefix function
# by passing the input value
piglatin = pl_prefix(inputword)

#print the piglatin value
print("The obtained piglatin value is: ", piglatin)

#call the pl_reverse function by passing
#the user input value and store it in reverseWord variable
reverseWord = pl_reverse(inputword)

#print the obtained reverseWord value
print("The reverse word with prefix value is: ", reverseWord)

Explanation / Answer

Answer:

#definition of pl_translate function

def pl_translate(word):
t = 0
consonants = "bBcCdDfFgGhHjJkKlLmMnNpPqQrRsStTvVwWxXzZ"
      while len(word) == 0:
       word1= " You cannot translate a non-existant word! ";
         for x in word:
            if (x == "a") or (x == "A") or (x == "e") or (x == "E") or (x == "i") or (x == "I") or (x == "o") or (x == "O") or (x == "u") or (x == "U") or (x == "y") or (x == "Y"):
                break
            t = t+1  
    prefix = word[:t]
    stem = word[t:]
    if consonants not in word:
        word1 =word + "yay"
    else:
        word1= stem + prefix + "ay"
return word1
#end of pl_translate function

#call the pl_translate function by passing
#the user input value and store it in translateWord variable

translateWord = pl_reverse(inputword)

#print the obtained translateWord value
print("After translate we get: ", reverseWord)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote