Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment, we have to take the code below and reverse it to make a PigLatin to English translator for Python. '''iglatinpay anslatortray if

For this assignment, we have to take the code below and reverse it to make a PigLatin to English translator for Python.

'''iglatinpay anslatortray

if the first two chars are consonant and a vowel, move the consonant and add 'ay' if the first two chars are both consonants, move both to the end and add 'ay' if the first letter is a vowel, add 'tay' to the end

run this script from the terminal: (for windows) py piglatin_lab5.py -from Type your sentence here like this

(or for mac) python piglatin_lab5.py -from Type your sentence here like this

''' from sys importargv import string '''the string module contains a variable called punctuation, which is all punctuation characters in one string '''

vowels = 'aeiouy' consonants = 'bcdfghjklmnpqrstvwxz'

def translateTo(startingIndex): translatedWords = '' #empty string for the result w = startingIndex #initial word index in theargv list while w <len(argv): #start at index 1 to skip the name of the program in the argv word = str(argv[w]) #chunks off the indexed word translatedWord = '' #empty string to hold the current word #strip commas, periods, etc. from the end of words if word[-1] in string.punctuation: endingPunctuation = word[-1] word = word[:len(word)-1] else: endingPunctuation = False

if len(word) > 1: #rearrange the letters in the word if word[0] in consonants and word[1] in consonants: translatedWord = word[2:]+word[:2]+'ay' elif word[0] in consonants and word[1] in vowels: translatedWord = word[1:]+word[:1]+'ay' elif word[0] in vowels: translatedWord = word+'tay' else: print("word not caught: " + word) elif len(word) == 1: translatedWord = word + 'yay' else: translatedWord = word

#if there was an ending punctuation, add it back on if endingPunctuation: translatedWord+=endingPunctuation

#add the translated word into the string of all the words, with a space at the end translatedWords += translatedWord + ' ' w += 1

#loop is done, print the translation print(translatedWords) #end of translation to piglatin

def translateFrom(startingIndex): print(argv) #do your translation here

################################## '''after defining the translations, we can check the second arg to see if a translation style is declared, else, just translate to pig latin ''' ##################################

if str(argv[1]) == '-to': print('running translation to because argv[1] is: ' + str(argv[1])) translateTo(2) elif str(argv[1]) == '-from': translateFrom(2) else: translateTo(1)

THANKS FOR THE HELP!!!!!!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 23rd International Conference Dexa 2012 Vienna Austria September 2012 Proceedings Part 1 Lncs 7446

Authors: Stephen W. Liddle ,Klaus-Dieter Schewe ,A Min Tjoa ,Xiaofang Zhou

2012th Edition

3642325998, 978-3642325991

More Books

Students also viewed these Databases questions