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

Pig Latin is a language game in which words in English are altered. The objectiv

ID: 3777888 • Letter: P

Question

Pig Latin is a language game in which words in English are altered. The objective is to conceal the words from others not familiar with the rules. The reference to Latin is a deliberate misnomer, as it is simply a form of jargon, used only for its English connotations as a strange and foreign-sounding language.

To translate a word into Pig Latin, move all letters up to, but not including the first vowel (a,e,i,o,u), to the end of the word and append the -ay suffix.

Example

Pig will be "igpay"

Latin will be "atinlay"

School will be "oolschay"

In will be "inay"

Out will be "outay"

Yes will be "esyay"

STOP and THINK BEFORE YOU CODE. Write a function that translates a string of English words to a string of Pig Latin words.

>> pig_latin('pig latin in matlab')

ans = "igpay atinlay inay atlabmay"

>> pig_latin('engineers rule the world')

ans = "engineersay uleray ethay orldway"

use matlab

Explanation / Answer


def toPigLatin(word):
    #if this is an empty word, don't do anything
    if len(word) < 1:
        return
  
    first_letter = word[0] #find the first letter of given word
    if first_letter in "aeiou": #the first letter is a vowel
        word_to_return = word + "ay" #we could also write: word += "-ay"
    else: #the first letter is a constanant
      
        word_to_return = word[1:]
        word_to_return += first_letter + "ay"
    return word_to_return