Getting Started

Before you can invent anything, you need a place to write and run code. This chapter gets you set up and running your very first Python program — in under 15 minutes.

Part 1: Choose Your Setup

There are two ways to run the code in this book. Both work for every chapter. Pick whichever suits you — you can always switch later.

Part 2: Path A — Google Colab

Google Colab gives you a free Python notebook in your browser. No installation, no configuration — just a Google account.

Your First Cell

Click inside the code cell and type exactly this:

print("Hello, World!")

Now run it: press Shift+Enter (or click the play button ▶ on the left of the cell).

What appears below the cell?

A Quick Calculation

Click "+ Code" at the top to add a new cell. In the new cell, try each of these one at a time (you can put them all in one cell too):

2 + 3
10 * 5
7 / 2
2 ** 10

What does ** do? What does / give you — is it a whole number or a decimal?

Your First Variable

A variable stores a value so you can use it later. In a new cell, type:

name = "your name here"
print("Hello, " + name + "!")

Replace "your name here" with your actual name. Run it.

Now change the name to someone else's and run again. The code is the same — only the data changed.

You're set up with Google Colab!

Every chapter in this book can be opened directly in Colab — look for the "Open in Colab" button at the top of each chapter page.

Now skip to Part 4 to write your first real program.

Part 3: Path B — VS Code + Python

This path sets up a full Python environment on your computer. It takes a few more minutes, but you'll have a professional-grade setup that works offline.

Verify Your Setup

Open a terminal in VS Code:

  • Windows/Linux: Press Ctrl+` (backtick) or go to Terminal → New Terminal
  • Mac: Press Cmd+` or go to Terminal → New Terminal

Type this and press Enter:

python --version

You should see something like Python 3.12.4 (the exact version doesn't matter as long as it starts with 3).

Mac users: If python doesn't work, try python3 --version instead.

Try the Python Interpreter

Before we open a notebook, let's use Python directly in the terminal. This is the Python interpreter — a place where you type one line at a time and Python responds immediately.

In the same VS Code terminal, type:

python

(Mac/Linux: use python3 if python doesn't work.)

You should see something like:

Python 3.12.4 (...)
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> is Python's prompt — it's waiting for you. Now try these one at a time:

>>> 2 + 3
>>> 10 * 5
>>> 2 ** 10
>>> print("Hello from the interpreter!")
>>> name = "Alice"
>>> print("Hello, " + name)

Notice that the interpreter shows results immediately — you don't even need print() for expressions like 2 + 3.

When you're done, type exit() to leave the interpreter and return to the normal terminal.

Create a Python File and Run It

The interpreter is great for quick experiments, but real programs live in files. Let's create one.

  1. In VS Code, go to File → New File (or press Ctrl+N / Cmd+N)
  2. Save it as hello.py — pick any folder you like (File → Save As, or Ctrl+S / Cmd+S)
  3. Type these lines in the file:
name = "Alice"
print("Hello, " + name + "!")
print(name, "can count to", 2 ** 10)
  1. Save the file again (Ctrl+S / Cmd+S)
  2. Open the terminal (Ctrl+` or Terminal → New Terminal)
  3. Navigate to the folder where you saved the file (use cd if needed) and run:
python hello.py

(Mac/Linux: use python3 hello.py if needed.)

You should see the output printed in the terminal. Change the name in the file, save, and run again — notice you have to save before running, unlike the interpreter.

Create a Notebook

  1. In VS Code, press Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the Command Palette
  2. Type "Jupyter: Create New Blank Notebook" and select it
  3. You'll see an empty notebook with a code cell
  4. VS Code may ask you to select a kernel — pick the Python version you installed (e.g. Python 3.12.4)

Now type this in the first cell:

print("Hello from VS Code!")

Press Shift+Enter to run it.

A Quick Calculation

Click "+ Code" (or press B when no cell is selected) to add a new cell. Try these:

2 + 3
10 * 5
7 / 2
2 ** 10

What does ** do? What does / give you?

Your First Variable

In a new cell:

name = "your name here"
print("Hello, " + name + "!")

Replace "your name here" with your actual name. Run it, then change the name and run again.

You're set up with VS Code!

You can open any .ipynb file from this book in VS Code — just download the notebook and open it with File → Open File. VS Code will render it just like Colab does.

Now continue to Part 4 for your first real program.

Part 4: Your First Program

Whichever path you chose, you now have a working notebook. Let's write a few small programs to make sure everything clicks — and learn a couple of important lessons along the way.

Predict Before You Run

Before running each line, write down what you think it will print. Then run it and check.

print(3 + 4)
print("3 + 4")
print("Result:", 3 + 4)

Why do the first two give different outputs?

Your First Bug

Type this exactly — with the deliberate mistake:

print("Hello World)

Run it. You'll get an error. Read the error message carefully:

  1. What kind of error is it?
  2. Can you figure out what's wrong just from the message?
  3. Fix it and run again.

Errors are not failures — they're Python telling you exactly what went wrong. Learning to read error messages is one of the most important programming skills.

Make It Yours

Write a program that:

  1. Stores your name in a variable called name
  2. Stores your favourite number in a variable called fav
  3. Prints a greeting with your name
  4. Prints what your favourite number squared is

Here's a skeleton to get you started:

name = "..."
fav = ...

print(name, "likes the number", fav)
print(fav, "squared is", fav ** 2)

Replace "..." and ... with your actual name and number.

Congratulations — you're ready to start inventing!

You now know how to:

  • Open a notebook (in Colab or VS Code)
  • Write and run code in cells
  • Use print() to see output
  • Store values in variables
  • Use Python as a calculator (+, -, *, /, **)
  • Read error messages and fix bugs

These are the only tools you need. Every algorithm in this book will be built from just these basics — one small step at a time.

What You Learned

Quick Reference

What How
Run a cell Shift+Enter
Add a new cell + Code button (Colab) or B key (VS Code)
Print something print("Hello")
Store a value x = 42
Add / subtract + / -
Multiply / divide * / /
Power (exponent) ** — e.g. 2 ** 10 = 1024
Text (string) Wrap in quotes: "Hello"
Read an error Look at the last line — it tells you what went wrong