LambdaLabTM
Computer Science · Class 11 · Getting Started
SetupFoundations⏱️ 7 min read

Interactive & Script Mode

Python can be run in two ways. One is like a chat (Interactive Mode) — you type one line, Python answers at once. The other is a file (Script Mode) — you write all the lines first, then run them together. You will use both. Let's see how each one works.

1First, install Python

Python is free. Go to python.org/downloads and run the installer. On Windows, one checkbox on the first screen is very important:

Watch Out
Tick “Add python.exe to PATH” before you click Install. It is not ticked by default. This checkbox is what lets you type py in any window and have the computer understand you. If you miss it, Python is installed but your computer cannot find it — and it will look like the installation failed.

On macOS and Linux, Python is usually already installed. Either way, here is how you check. Open a terminal and type this:

Terminal
# Windows — open Command Prompt, then type:
py

# macOS / Linux — open Terminal, then type:
python3

If Python is there, it shows its version and then three symbols:

Terminal
Python 3.13.1 (main, Dec  3 2024, 17:59:52)
Type "help", "copyright", "credits" or "license" for more information.
>>>
Note
Those three symbols — >>> — are called the Python prompt. You do not type them. They are Python saying “I am ready, give me a line”. When you see them, you are in interactive mode.

2The two modes, side by side

Instead of just reading about them, watch them. Press the buttons below. The same three lines of code are run in both modes. Notice when Python gives the answer. That is the main difference.

Terminal — python3
>>>
Like a chat

You type one line. Python answers at once, then waits for you again. Good for a quick test. Not good for a long program.

3Interactive mode: like a chat

It is called interactive because you and Python take turns, like two people talking. You type one line. Python answers straight away. Then it waits for your next line. Type 2 + 3 and the answer 5 appears at once.

This is useful for quick tests. Say you are not sure what print('Hi', 'there') will show. You do not have to guess. Open the prompt, type it, and Python tells you at once. Even expert programmers use it this way.

How to open the prompt on your own computer

You will need this for the next few lessons, so follow these steps once and keep the window open while you practise.

On Windows
  1. 1Press the Windows key, type cmd and press Enter. A black window called Command Prompt opens.
  2. 2Type py and press Enter.
  3. 3Python prints its version and shows >>>. You are in.
  4. 4Type a line, press Enter, and Python answers at once.

If py does not work, try python.

On Linux or macOS
  1. 1Open the Terminal app. On most Linux systems Ctrl + Alt + T opens it. On a Mac, press Cmd + Space, type Terminal and press Enter.
  2. 2Type python3 and press Enter.
  3. 3Python prints its version and shows >>>. You are in.
  4. 4Type a line, press Enter, and Python answers at once.

Type python (without the 3) only if python3 is not found.

Here is what it looks like once you are inside:

Python prompt — interactive mode
>>> 2 + 3
5
>>> print('Hello, world!')
Hello, world!
Tip
To leave the prompt, type exit() and press Enter. (Keyboard shortcut: Ctrl + Z then Enter on Windows, Ctrl + D on Linux and macOS.) Remember: once you leave, everything you typed is gone.

But interactive mode has three big problems:

Nothing is saved

Close the window and all your lines are gone. Tomorrow you start again from an empty prompt.

You cannot go back

Once you press Enter on a line, you cannot go up and edit it. You have to type the whole line again.

It keeps interrupting

Python replies after every single line. For a long program, that gets in the way.

Key Takeaway
Interactive mode is for quick testing. It is not the place to write a real program.

4Script mode: a saved file

In script mode you write all your lines first, in one file. Nothing runs while you type. You save the file with a name that ends in .py — that is how the computer knows it is Python. Then you give the whole file to Python to run, and the output appears.

hello.py
# write all the lines, save the file, THEN run it

print('Hello, world!')
print('My name is Ramesh.')
print(2 + 3)

To run it, type this in the terminal:

Terminal
python3 hello.py     # macOS / Linux
py hello.py          # Windows

This fixes all three problems. The file is saved, so it is still there tomorrow. You can go back and edit any line before you run it. And Python does not interrupt — it reads the full file from top to bottom and runs everything. This is how real programs are written.

Tip
The .py ending matters. If you save the same code as hello.txt, Python will not run it.

5Which mode should I use?

You want to…UseWhy
Check what one line of code doesInteractiveOne question, one answer, three seconds.
Write a program for your practicalScriptYou need to save it, edit it and run it again.
Test one line before using itInteractiveIt is just a rough notebook. Nothing is lost.
Submit your work to a teacherScriptIn interactive mode there is no file to submit.
Note
Our plan. We will start at the >>> prompt, because it answers back and that makes learning easier. After the next lesson on print(), we will move to script mode and stay there.
Quick Check

You type three lines at the >>> prompt, then close the window. What do you have?

Quick Check

Why must a Python program's file end in .py?