Preplp
Daily Python
Day 10Python~40 min

Files — read & write

Persist notes with open()

Track progress0/15 days
x

What you'll learn

openreadwriteappendFileNotFoundError
  • Read and write text files
  • Handle missing files gracefully
  • Build a note-taking app

Lesson & examples

Read the code, then the explanation — try changing values before the project.

Append a note
with open("notes.txt", "a") as file:
    file.write("New line\n")

Today's exercise: Note-Taking App

Add, view, and clear notes stored in a text file.

Steps

  1. 1

    FILE_NAME constant

    Use myNotes.txt for storage.

  2. 2

    Menu

    Add note (append), view (read), delete all (truncate).

Full project source — copy into a folder or use the zip above

starter.py
FILE_NAME = "myNotes.txt"

def show_menu():
    print("\n1. Add note  2. View notes  3. Delete all  4. Exit")

def add_note():
    note = input("Note: ")
    with open(FILE_NAME, "a") as f:
        f.write(note + "\n")
    print("Saved.")

def view_notes():
    try:
        with open(FILE_NAME, "r") as f:
            print(f.read() or "No notes yet.")
    except FileNotFoundError:
        print("No notes yet.")

while True:
    show_menu()
    c = input("Choice: ")
    if c == "1":
        add_note()
    elif c == "2":
        view_notes()
    elif c == "4":
        break

One rehearsal platform

Certification mocks, daily lessons, project labs, and in-browser drills

Structured for exam day and portfolio proof — timed tests, guided builds, and quick reps on one platform.