Question: Exercise 4 : reading and writing to file Write a program that reads the content of the file database.txt and replaces all instances of

Exercise 4: reading and writing to file
Write a program that reads the content of the file "database.txt" and replaces all instances of the word "morning" with "evening" (all lower case). The updated content should be written to a new file called "new-database.txt".
Just like assignment 3, the word needs to be "morning" by itself. If it is a part of another word such as "morningside" then it shouldn't be replaced.
For example, if "database.txt" contains the following content:
Good morning to you!
Good morning to you, residents of morningside!
Then after running the program, "new-database.txt" should have the following content:
Good evening to you!
Good evening to you, residents of morningside!
For simplicity, you can use .split() and not worry about punctuations touching the word "morning" such as "morning!"
Exercise 4 : reading and writing to file Write a

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 Programming Questions!