Kids Coding

Tiny Files

Save a high score or a story to a file. Read it back next time.

KidsIntermediateTiny Files

Save something for later

A file keeps text after the program ends. You open it, write or read, and close it. with open(...) closes it for you.

Write, then read

with open("note.txt", "w", encoding="utf-8") as file:
    file.write("High score: 12\n")

with open("note.txt", "r", encoding="utf-8") as file:
    text = file.read()
print(text)

"w" writes (and replaces). "r" reads. encoding="utf-8" keeps letters safe.

What this is for

  • A high score.
  • A story you generated.
  • A list of names.

Real life

A high score on a handheld game that is still there tomorrow.

Memory forgets when the program ends. A file is the sticker on the fridge.

Save the high score

with open("highscore.txt", "w", encoding="utf-8") as file:
    file.write("15")

with open("highscore.txt", "r", encoding="utf-8") as file:
    best = file.read()
print("Best so far:", best)

Change one word. Run it. That is how this idea shows up outside the lesson.

Try it

Exercise 1: Write hello to hi.txt, then read the file and print it.

Show solution
with open("hi.txt", "w", encoding="utf-8") as file:
    file.write("hello")
with open("hi.txt", "r", encoding="utf-8") as file:
    print(file.read())

FAQ: Tiny Files

Common questions about this page.

What is StudyGrid Kids?

StudyGrid Kids is a free coding path for children: Basic, Intermediate, and Advanced. Lessons use Python in the browser. No account and no install.

Should I run tiny files examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn tiny files in this Kids Coding Python lesson (Tiny Files).

Which kids level should we start with?

Start at Basic if the child has never written code. Choose Intermediate if they can print, use variables, and write a simple if. Choose Advanced if they already use loops and lists.

Do kids need an account or an app?

No. Kids pages are public. Code runs in the Try Python editor at /try. We do not ask children for a name or an email.

What language do kids learn?

Python, with a first HTML page in Intermediate and Advanced. After Advanced, the main Python tutorial is the next step.

Is the kids coding track free?

Yes. The Kids home, the three levels, and the Python editor on StudyGrid (studygrid.in) are free.