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
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)
Comments
Leave a comment