JEPA4Japan · tutorials

Meet Python: Teach a Tiny Helper

1,007 words 5 min read #Python

Use a simple picture story to write, run, change, and repair your first interactive program.

Course progress Course outline 24 of 24 lessons available

Python is a tiny helper

Imagine a small helper who is very fast, very patient, and very literal. It will follow your recipe exactly—but it cannot guess a missing step. That helper is Python.

  1. Write a tiny recipe
  2. Run give it to Python
  3. See look at the result
  4. Change try one new thing
Your whole programming loop: write → run → see → change.

Your first recipe is one line:

print("Hello, Python!")

print() means “show this on the screen.” Python replies:

Hello, Python!

By the end of this chapter, you will make a tiny program that asks your name and your dream, then prints a card just for you.

One big idea: a program is a recipe, and Python is the helper that follows it.

Three places, three jobs

You will see three kinds of text. They may look alike, but they have different jobs.

  1. Terminal python3 hello.py
    asks the computer to run
  2. Python code print("Hello")
    is the recipe
  3. Output Hello
    is Python's answer
Command, code, and answer belong in different places.

Open a terminal and check for Python 3:

python3 --version

You should see something beginning with Python 3. On Windows, try py --version instead. Use whichever command works on your computer for the rest of this chapter.

For one quick experiment, start Python:

python3

When you see >>>, type:

2 + 3

Python answers 5. Type exit() when you are done. This quick playground is called the REPL.

Terminal = start things. Python code = instructions. Output = the result.

Save a hello recipe

Quick experiments disappear. A file keeps your recipe.

  1. Make a plain-text file named hello.py. Do not call it python.py.
  2. Put this inside and save it:
print("Hello, Python!")
  1. In the terminal, move to the folder containing the file and run:
python3 hello.py

You should see:

Hello, Python!

Now change the recipe:

print("I changed the recipe!")

Save, run, and look again. The new words appear because Python reads the saved file from top to bottom every time.

If you still see the old words, save the file before you run it again.

Let your program listen

print() is Python’s mouth. input() is Python’s ear: it asks a question and waits.

  1. Ask input() waits
  2. Keep a name labels the answer
  3. Show print() speaks
Ask → keep the answer → show it.

Create dream_card.py with exactly these five lines:

print("My Python Dream Card")
name = input("Your name: ")
dream = input("What do you want to build? ")
print("Dreamer:", name)
print("Dream:", dream)

Run it:

python3 dream_card.py

One run might look like this:

My Python Dream Card
Your name: Maya
What do you want to build? a game
Dreamer: Maya
Dream: a game

name and dream are labels for the two answers. The next chapter will explain these labels precisely. For now, run the program again with different answers and watch the card change.

Source code stays the same; input can change on every run.

Errors are clues

Sometimes the recipe has a torn word. Python stops and leaves a clue called a traceback.

  1. Stop an error appears
  2. Read start at the last line
  3. Fix change one thing
  4. Run again check your idea
An error is a clue, not a monster.

Try this broken line on purpose:

print("Hello)

The final line of the traceback says SyntaxError. Python is telling you that the quote was never closed. Add the missing ", save, and run again:

print("Hello")

If Python says it cannot open your file, check that the terminal is in the right folder. If it says NameError, check the spelling and make sure the name received an answer before you used it.

Read the last line, find the file and line number, fix one thing, then run again.

Three tiny missions

  1. Make it yours. Change the Dream Card heading and predict the new output before running it.
  2. Add one answer. Ask for a favorite color, save it as color, and print it on the card.
  3. Be an error detective. Remove one closing quote, find SyntaxError, repair it, and confirm the program works.

Stuck? Check four small things: saved file, right folder, matching quotes, lowercase print.

You are ready for Chapter 2 when…

  • you can explain terminal, Python code, and output;
  • you can create, save, and run a .py file;
  • you can use print() and input();
  • you can change the Dream Card and see a new result;
  • you can read the last line of an error and repair one mistake.

Next, you will open the labeled boxes and learn exactly how Python stores values, variables, and types.