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

In python 3 (50 total for parts a and b) Write a function that translates Englis

ID: 3837463 • Letter: I

Question

In python 3

(50 total for parts a and b) Write a function that translates English language text to "Pig Latin' according the following rules for translating one word: If the word begins with a vowel (a.e.i.o.u), then it is simply translated by appending 'way- to the end c it. As examples, 'act' becomes actway' and old' becomes 'oldway' and so on. If the word does not begin with a vowel (it starts with a consonant), then it is translated by moving all consonant letters up to the first vowel to the end of the word with 'ay' appended to the very end. As examples, gasp' becomes aspgay' and school becomes oolschay' and so on. This rule also applies when the word has no vowels at all - in that case, 'ay' is simply appended. Special cases: The letter y is counted as a vowel in this context (when a word begins with a consonant). Examples: system' becomes ystemsay' and 'crystal becomes ystalcray' and so on. The letter 'u' is counted as a consonant when it follows the letter 'q' in a word, so queen' becomes eenquay' and square' becomes aresquay' for examples, Capitalization is properly maintained. Words that are all capital letters are translated to all capital letters ('IBM becomes 'IBMWAY' and 'CRUMB becomes 'UMBCRAV). Also, words that are properly capitalized are translated with proper capitalization ('Apple' becomes Appleway and Mark' becomes Arkmay) We suggest you solve this problem in two parts, and the points will be allocated accordingly: a. Get the function working for just one word. That is. full credit for this part is earned by translating text that consists of nothing except alphabetic characters. Return (don't print) the translated text as a string. See (and be sure to match) the first few sample runs below. b. Improve the function so that it works with text that consists of any characters, and presumably multiple words. Translate each word separately. A word is defined as any consecutive sequence of alphabetic letters, and they may be separated by any sequence of non-letter character' All non-letter characters should just be copied to the Pig Latin translation. The function header must exactly match the following: det pigLatin(text): Here are some sample runs of our pigLatin solution: > > > from project2 import pigLatin > > > piglatin('banana') 'anariabay' > > > p = pigLatin('Apple") > > > print(p) # depends on returned value of p Appleway > > > pigLatin('Square') 'Aresquay' > > > pigLatin('My hovercraft ii full of eels.') 'Ymay overcrafthey isway ullfay ofway eelsway.' > > > pigLatin(FDA says: "Three squares is the way to go!"') AFDAY ayssay: "Eethray aressquay isway ethay ayway otay ogay!"'

Explanation / Answer

import re

vowels = list('aeiouAEIOU')
VOWELS = list('AEIOU')

def startWithVowel(text):
if (text[0] in vowels or text in VOWELS):
   if(text.isupper()):
   return text + "way".upper()
   elif(text.islower()):
   return text + "way"
   elif(text[0].isupper()):
   return text + "way"
   else:
   return 0

def isStartWithQ(text):
if text[0]=='q' or text[0]=='Q':
return True
else:
return False

def pigLatin(text):
  
   # If the first character in input is a vowel add 'way' to input and print.
   if (startWithVowel(text)!=0):
   pig_output=startWithVowel(text)
   else:
       r = re.search("(.*?)([aeiou].*)", text)
  
       # Capture the consonants up to the first vowel
       captured_consonants = r.groups()[0]
  
       # Slice text up to the first vowel and create a substring beginng from the first vowel until the end of the string.
       captured_substring = r.groups()[1]
  
       # Concatenate substring of text with captured_consonants and 'ay'
       pig_output = captured_substring + captured_consonants + "ay"
       print(pig_output)


tex=input('Enter a text : ');
pigLatin(tex);
#print(startWithVowel(tex))
#print(isStartWithQ(tex))

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