Answer to Question #350841 in Python for D.K

Question #350841

Write python code to read and write data to a file named "university.txt" with the following criteria:






- Change the "university hymn" in "university.txt" file to your favorite song





- Write "Submitted by: Firstname Lastname






1
Expert's answer
2022-06-15T07:06:56-0400
reading_file = open("university.txt", "r")
new_file_content = ""
for line in reading_file:
    stripped_line = line.strip()
    new_line = stripped_line.replace("university hymn", "favorite song")
    new_file_content += new_line +"\n"
reading_file.close()

writing_file = open("university.txt", "w")
writing_file.write(new_file_content)
writing_file.close()

new_line = "Submitted by: Firstname Lastname.\n"
with open("university.txt", "a") as a_file:
    a_file.write("\n")
    a_file.write(new_line)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS