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

Use Python programing. First please download all 4 files listed below into the s

ID: 3803661 • Letter: U

Question

Use Python programing.

First please download all 4 files listed below into the same folder. Start by reading the poemTranslator.pdf file to learn about the assignment. You will eventually be filling in code in the RPB.py file that reads from one or the other of the poem text files (your choice)!

(Note: if your browser opens files when you click on the links instead of letting you download them, right-click on the file link and select "Save As" or "Save Link As" to download and save the files.)

poem translator pdf -http://www.cs.uni.edu/~diesburg/courses/cs1510_sp17/homework/PA07/poemTranslator.pdf

RPB.py - http://www.cs.uni.edu/~diesburg/courses/cs1510_sp17/homework/PA07/RPB.py (after opening this link copy the whole thing and paste it on python to start working on it)

marry poem - http://www.cs.uni.edu/~diesburg/courses/cs1510_sp17/homework/PA07/maryPoem.txt

Lost generation poem -http://www.cs.uni.edu/~diesburg/courses/cs1510_sp17/homework/PA07/LostGeneration.txt

Explanation / Answer

Below is the full code written as per asked, With punctuations, if you want to remove punctuations just add the remove function on the top, and save it as maryPoem_without_punc.txt and then execute the other functions on that file.

This code was tested for maryPoem.txt(Raw file with punctuations).

The code should be in the same directory of the txt file

import random
import os.path


def write_lines_to_file(filename, lines):
with open(filename, 'w') as output:
output.writelines(lines)
print(" {} created. ".format(filename))

def readingLinesBackwards(filename):
with open(filename) as input:
lines = input.readlines()

dirname, basename = os.path.split(filename)

new_filename = os.path.join(dirname, "readingLinesBackwards" + basename)
write_lines_to_file(new_filename, reversed(lines))
  
  
def readingWordsBackwards(filename):
with open(filename) as input:
lines = input.readlines()

dirname, basename = os.path.split(filename)

new_filename = os.path.join(dirname, "lines_and_words_backwards_" + basename)
reverse_words_in_line = lambda line: ' '.join(reversed(line.split())) + ' '
altered_lines = (reverse_words_in_line(line) for line in reversed(lines))
write_lines_to_file(new_filename, altered_lines)
  
def randomizeLines(filename):
with open(filename) as input:
lines = input.readlines()

dirname, basename = os.path.split(filename)
new_filename = os.path.join(dirname, "lines_randomized_" + basename)
random.shuffle(lines)
write_lines_to_file(new_filename, lines)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote