Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

(a) (required) This text file of I Corinthians 13 is a bit spaced out (it has lots of extra, unwanted spaces). You need to write

(a) (required) This text file of I Corinthians 13 is a bit spaced out (it has lots of extra, unwanted spaces). You need to write a code in Python that will fix the file so that there is only one space between each two words. Start by downloading the file and then making sure your IDLE is saving into the same directory where the text file is located. If you mess the file up, you can always download it again. Email me your code (not the text file) before our next class.

Hints for part(a):

(i) As soon as you open your textfile (e.g., with open("Love.txt","r+") as f: ), I recommend saving the entire file contents as either file = f.read() or file = f.readlines(). f.read() saves the entire contents to a single string. f.readlines() saves each line in the textfile as a separate string in a list of strings.

(ii) You could potentially read and change the same file, but I strongly recommend reading from the original file, making your changes, and then saving to a NEW text file (which means you should probably do another with open("Love2.txt","w+") as f: statement, or something similar.)

(b) (optional bonus) Extend the program in part (a) so that, in addition to fixing the spacing issue, all instances of 'love' or 'Love' are replaced with "LOVE" and so that every period signals a new line. This is what your finished text file should look like.

MUST BE ABLE TO COPY AND PASTE INTO PYTHON AND IT RUN PERFECTLY

MUST INCLUDE OPTIONAL BONUS

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions