Question

In: Computer Science

Pig Latin is a language constructed by transforming English words. The following rules are used to...

Pig Latin is a language constructed by transforming English words. The following rules are used to translate English into Pig Latin:

*If the word begins with a consonant, then all consonants at the beginning of the word, up to the first vowel are removed then added to the end of the word, followed by “ay”. For example, “computer” becomes “omputercay” and “think” becomes “inkthay”.

*If the word begins with a vowel, then “way” is added to the end of the word. For example, “algorithm” becomes “algorithmway” and “office” becomes “officeway”.

*If the word ends in a punctuation mark, then the punctuation mark should remain at the end of the word after the transformation has been performed. For example, “science!” should become “iencescay!”. You can assume that the punctuation mark is only a single character. The program reads a line of text from the user and translates it into Pig Latin and displays the result.

This is in python.

Solutions

Expert Solution

input code:

output:

code:

import string
'''take user input'''
text=input("Enter a Text: ")
'''break the string and store into list'''
text=list(text.split(" "))
'''declare the list of vowels'''
vowels=['A','E','I','O','U','a','e','i','o','u']
output=[]
'''convert all the words into pig Latin'''
for i in text:
'''check ends with punctuation or not'''
if i[len(i)-1] not in string.punctuation:
'''if not end than check start with vowels or not'''
  
if i[0] in vowels:
'''true than add way'''
i=i+"way"
else:
  
'''else for loop until we get vowels'''
for ch in range(len(i)-1):
  
'''if we find vowels'''
if i[ch] in vowels:
'''than do this and break the loop'''
i=i[ch:]+i[0:ch]+"ay"
break
  
'''add value into list'''
output.append(i)
  
else:
  
'''if end than check start with vowels or not'''
if i[0] in vowels:
'''true than add way and than add punctuation'''
i=i[:len(i)-1]+"way"+i[len(i)-1]
  
else:
  
'''else for loop until we get vowels'''
for ch in range(len(i)-1):
  
'''if we find vowels'''
if i[ch] in vowels:
'''than do this and break the loop'''
i=i[ch:len(i)-1]+i[0:ch]+"ay"+i[len(i)-1]
break
'''add value into list'''
output.append(i)

'''make list to string'''
output=" ".join(output)
'''print output'''
print("Pig Latin text: ",output)


Related Solutions

question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules:...
question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules: For every word in a sentence, the firstletter of the word is shifted to the end of the word and the suffix “-ay” is added at the end of the word. For example, “hey pat”becomes “eyhay atpay”.Implement thepiglatin(str)function so it translates sentences to pig latin. If you have time remaining, try implementing afunction to ”decrypt” piglatin, i.e. given a sentence in piglatin, return the...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin that doesn't allow follow all the Pig Latin Syntax rules.) Use predefined methods of the Array and String classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters "ay" onto the end. For example, the word "example" would become "xampleay" and "method" would become "ethodmay." Allow the user to...
python Create a dictionary and insert several English words as keys and the Pig Latin (or...
python Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values. Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%. Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which words in English are altered, usually by removing letters from the beginning of a word and arranging them into a suffix. The rules we will use for the pig-latin in this program are as follows: If a word starts with a consonant, split the word at the first instance of a vowel, moving the beginning consonants to the end of the word, following a...
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console...
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console Pig Latin Translator This program translates a sentence and removes all punctuation from it. Enter a sentence: 'Tis but a scratch. Translation:      Istay utbay away atchscray Specifications Convert the English to lowercase before translating. Remove all punctuation characters before translating. Assume that words are separated from each other by a single space. If the word starts with a vowel, just add way to the...
Create a program that translates English into Pig Latin. The function will take the first letter...
Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case ​ins​ ensitive. You must write the functiontranslate() ​that takes in a single English word and ​returns​ its Pig Latin translation. Remembertranslatemusttake​onlyonewordasinput.​ ############################################################# # translate() takes a single english word translates it to #pig latin...
You can turn a word into pig-Latin using the following two rules: If the word starts...
You can turn a word into pig-Latin using the following two rules: If the word starts with a consonant, move that letter to the end and append 'ay'. For example, 'happy' becomes 'appyhay' and 'pencil' becomes 'encilpay'. If the word starts with a vowel, simply append 'way' to the end of the word. For example, 'enter' becomes 'enterway' and 'other' becomes 'otherway'. For our purposes, there are 5 vowels: a, e, i, o, u (we consider y as a consonant)....
Make a list of French and Latin vocabulary which entered the English language during the Middle English period
Make a list of French and Latin vocabulary which entered the English language during the Middle English period (after the Norman Conquest) and divide it into at least 6 categories such as military, law, government, architecture, household, food, and religion.
Are there more words in the English language That start with an "r" OR For which...
Are there more words in the English language That start with an "r" OR For which "r" is the third letter How do you calculate these statistical hypothesis?
Use Python Return a password string constructed with the following rules: (1) If there are only...
Use Python Return a password string constructed with the following rules: (1) If there are only 0 or 1 numeric among 3 parameters, concatenate the string form of all parameters directly. (2) If there are 2 numeric parameters, calculate the sum of 2 numeric values if they are both int, or calculate the product of them and round to 2 decimal places if any of them is float. Finally, append this sum/product to the string parameter. You may assume that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT