Question: I need python 3 help. Thank you This is question 2 function that i made def change(english_word): assert isinstance(english_word, str) def letter_mover(letter): if it takes

I need python 3 help.

Thank you

This is question 2 function that i made

def change(english_word):

assert isinstance(english_word, str) def letter_mover(letter): """if it takes vowel letter, it changes to next vowel. If it takes consonant, it changes to next third consonant.""" vowels_double = ['a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'] consonant_double = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'n', \ 'm', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', 'b', 'c', 'd', 'f', \ 'g', 'h', 'j', 'k', 'l', 'n', 'm', 'p', 'r', 's', 't', 'v', 'w', 'x', \ 'y', 'z'] if letter in vowels_double: return vowels_double[vowels_double.index(letter)+1] if letter in consonant_double: return consonant_double[consonant_double.index(letter)+3] return letter english_word = english_word.lower() return "".join(map(letter_mover, english_word))

Q5: Mapping a Great Text!

Upon finishing your word translator, one of your literarily-minded friends suggested translating some books into the language of the local denizens. You agreed, so you decided to split the task in two parts. Your friend would give you a file and you would write a function that

  • takes in a filename as a formal parameter
  • reads that file
  • translates it
  • and finally writes a new, translated, file!

This program would come to be known as portal translator. The same algorithm will be used as in question 2. Thus, your task is to write a function called portal_translator that takes in the filename and outputs a translated file, i.e. it writes the translated content to a new file. It should also return the number of words translated.

Hints:

1. Open the file using open(filename, 'r')

2. Use map to convert the whole file to the new language in conjunction with your previous function. Question 2 will be useful here.

3. Output the new file using open(filename, 'w')

4. Make sure to close both files upon finishing the function.

5. The given file will only have words. No punctuation or anything else.

Note: The new file should have the same name as the input file, but with "_translated" at the end.

E.G.

file1.txt -> file1_translated.txt

You will be supplied with a practice file. Since this function is more focused, you DO NOT NEED TO WRITE YOUR OWN DOCTESTS.

Furthermore, you should also wrap the file opening procedure in a try-except block, which should return a message akin to that in the doctest if the file does not exist.

Feel free to use this return statement to be sure:

return "File " + filename + " does not exist."

Checking your results!

To make sure that your code is correctly translating the supplied test file, we have also given you a file with the correct answers.

After running your code, you can use the diff terminal command to compare the two files with the following syntax:

diff test_file_translated.txt supplied_output.txt | cat -vet

If the output is empty, then the two files are identical.

def portal_translator(filename): """ >>> portal_translator('test_file.txt') 260 >>> portal_translator('missing_file.txt') 'File missing_file.txt does not exist.' """ # YOUR CODE GOES HERE #

Submitting question 6 files: Submit at least 3 inputs that you used to test your functions. The names must be:

  • file1.txt
  • file2.txt
  • file3.txt
  • ...

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!