# Function: write notes to file
def write_notes(filename):
notes = "" # Start with an empty string
line = input("Write a note (type STOP to finish): ")
while line != "STOP": # Keep asking until the user types STOP
notes = notes + line + "\n"
line = input("Write a note (type STOP to finish): ")
with open(filename, "w") as file:
file.write(notes) # Save the notes into the file
print("Your notes have been saved!")
# Function: read a file and print line numbers
def read_file_with_line_numbers(filename):
with open(filename, "r") as file:
print(f"Reading line by line from {filename}:")
line_number = 0 # Number of lines counted so far
for line in file:
line_number = line_number + 1
print(f"{line_number}: {line}")
write_notes("notes.txt") # First: write some notes
read_file_with_line_numbers("notes.txt") # Then: read them back with line numbers
# 1. Instead of printing out lines with line_numbers, print your own custom message