python1name = input("Name? ")2text = input("Age? ")3age = int(text)4print("Hi,", name)5print(f"Next year: {age + 1}")age = text + 1TypeErrorage.pyName?'Sam'Age?'15''15'15'Sam'age + 116
Code card: age.py; the highlighted line is the one runningPython interpreter: reads your code and carries it outTerminal: input() reads what you type here; print() writes hereMemory boxes: the values stored in name, text and ageprint() sends output from the program to the terminal; input() brings what you type back in, always as a string. Each step lights the parts it is about. A token hops along the step's arrow: a prompt from a line to the terminal, each answer from the terminal into its memory box, '15' from text to age (turning into the number 15 on the way), and values back out to the terminal when they are printed. In the last step line 3 becomes age = text + 1: adding a number to a string stops the program with a TypeError.

Output and input

  1. Output is text a program shows you; print() writes it to the terminal. Input is text you type back; input() reads it. Run python age.py and Python works through the file from top to bottom.

Reading input

Using the answers

A common mistake

Try it yourself

;; step 1/9
print("Hello")         # output: program -> you
reply = input("? ")    # input:  you -> program

$ python age.py       # run the whole file

On macOS and Linux the command is often python3 rather than python; on Windows the py launcher also works. The $ is the terminal's own prompt: you do not type it. The figure shortens the error: the real traceback also names the file, the line and the code, and the terminal wraps the long last line.