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

\'Pig Latin’ Translation rules 1. If a word has no letters, don\'t translate it.

ID: 664169 • Letter: #

Question

'Pig Latin’ Translation rules

1.   If a word has no letters, don't translate it.
2.   All punctuation should be preserved.
3.   If the word begins with a capital letter, then the translated word should too.
4. Separate each word into two parts. The first part is called the prefix and extends from the beginning of the word up to, but not including, the first vowel. (The letter y will be considered a vowel for this.) The Rest of the word is called the stem.
5.   The Pig Latin text is formed by reversing the order of the prefix and stem and adding the letters ‘ay’ to the end. For example, sandwich is composed of s + andwich which would translate to andwichsay.
6.   If the word contains no consonants or starts with a vowel, let the prefix be empty and the word be the stem. The word ending should be yay instead of merely ay. For example, I would be Iyay and understood would be understoodyay.

Phase 1

Your first task is to produce a function called pl_prefix that takes one argument, a string containing a word, and returns the portion of the word up to, but not including the first vowel. For example, if you sent 'banana' to your function, it should return 'b'. Sending 'Sibley' should return 'S', 'stream' should return 'str', and 'break' should return 'br'. Test your function with other words and print out the results.

Be sure the function is named "pl_prefix" and the program is written in Python

Explanation / Answer

def no_letter(s):
   for char in s:
       if ((ord(char) >= 65 and ord(char) < 91) or (ord(char) >= 97 and ord(char) < 122)):
           return True
   return False

def sep(s):
   i = 0
   while (i < len(s)):
       char = s[i]
       if (char == 'a' or char == 'e' or char == 'i' or char == 'o' or char == 'u' or char == 'A' or char == 'E' or char == 'I' or char == 'O' or char == 'U'):
           break
       i += 1
   pre = s[0:i]
   suf = s[i:]
   return pre,suf

def pl_prefix(s):
   if (no_letter(s) == True):
       pre, suf = sep(s)
       r = None
       if (ord(pre[0]) >= 65 and ord(pre[0]) <= 90):
           r = suf[0].upper()
           r = r+suf[1:]
           suf = r
       if (len(pre) == 0):
           pre = "yay"
       else:
           pre = pre.lower()+"ay"
       s = suf + pre
   return s  

print pl_prefix("Sandwich")