Python Exercise 6
Pig Latin Translator (30pts)
Write a program that accepts and reads a text file (provided) as input, converts each word to
“Pig Latin.”, and writes the results to another text file. There are several versions of Pig Latin,
but in this version, you will do the following:
1) remove the first letter
2) place it at the end of the word
3) add the string ‘ay’. If the word consists of one letter, just add the string ‘ay’ to it.
An example of how translated text would look (using the rules above) is shown below:
English: I slept most of the night
Pig Latin: iay leptsay ostmay foay hetay ightnay
Your code should use a function that accepts the contents of the file as a string, converts the
contents to Pig Latin and returns the converted (and reconstructed) string.
Tips:
•
•
•
•
•
For variety, you may prompt the user to enter the name of an input file as well as
choose the name of their output file. Make sure to include the extension (text files are
preferred.)
For convenience, you may switch the text to one case (You can use upper, lower or title
functions for this purpose.)
Make sure you split the words as they are read from the file (as the contents would be
read and collected as one large string. You can use spaces (i.e. the default) to determine
how the words should be separated.
You are allowed to keep attached punctuations as part of the word. For example, if the
word is ‘code.’ the Pig Latin version may be translated as ‘ode.cay’.
You may change the input text file to a file of your choice as long as it is of a similar
length (at least 314 words). Please use ‘clean’ (read: non-offensive) text. Just make sure
to include it with your submission.
Encrypting code (30pts)
Write a program that uses a dictionary to encrypt a text file. You can use the dictionary
provided below or modify it to create your own version.
Encrypt_Code = {'A':')','a':'0','B':'(','b':'9','C':'*','c':'8',\
'D':'&','d':'7','E':'^','e':'6','F':'%','f':'5',\
'G':'$','g':'4','H':'#','h':'3','I':'@','i':'2',\
'J':'!','j':'1','K':'Z','k':'z','L':'Y','l':'y',\
'M':'X','m':'x','N':'W','n':'w','O':'V','o':'v',\
'P':'U','p':'u','Q':'T','q':'t','R':'S','r':'s',\
'S':'R','s':'r','T':'Q','t':'q','U':'P','u':'p',\
'V':'O','v':'o','W':'N','w':'n','X':'M','x':'m',\
'Y':'L','y':'l','Z':'K','z':'k','!':'J','1':'j',\
'@':'I','2':'i','#':'H','3':'h','$':'G','4':'g',\
'%':'F','5':'f','^':'E','6':'e','&':'D','7':'d',\
'*':'C','8':'c','(':'B','9':'b',')':'A','0':'a',\
':':',',',':':','?':'.','.':'?','','>':'
Purchase answer to see full
attachment