Sample course · Beginner · 12 lessons

Python for complete beginners

Learn to program by building a working expense tracker, one small step at a time

A gentle, practical introduction to Python 3 for people who have never written code: installing Python, variables, text and numbers, decisions, loops, lists, dictionaries, functions, files, errors and the standard library. Every lesson adds a piece to one real program, a personal expense tracker. By the end you can write, run, debug and organise small Python programs of your own.

What you'll learn

  • Install Python 3 on Windows, macOS or Linux and run a program from a file
  • Store and calculate with numbers and text using variables, input() and f-strings
  • Make decisions with if, elif and else, and repeat work with while and for loops
  • Organise data in lists and dictionaries, including totals grouped by category
  • Write functions that take parameters and return results
  • Save data to a file and load it back, using the csv module
  • Read tracebacks and handle expected problems with try and except
  • Use standard library modules and arrange a finished script around a main function

Who it's for

  • Complete beginners who have never written a line of code and want a practical first language
  • Spreadsheet users who want to automate small personal or office tasks with Python
  • People who started a coding tutorial before and got lost in jargon or skipped steps

Syllabus

  1. 1.First steps: running Python and working with values

    Install Python, run your first program from a file, and learn how Python stores numbers and text and talks to the person using it.

    1. Installing Python 3 and running your first program
    2. Values, variables and arithmetic· checkpoint
    3. Strings, input() and printing tidy results
  2. 2.Decisions, loops and lists

    Teach the tracker to react to what it is told, take as many purchases as needed, and remember each one in a list.

    1. Making decisions with if, elif and else· checkpoint
    2. Repeating work with while and for loops
    3. Lists: keeping every purchase in order· checkpoint
  3. 3.Organising and keeping your data

    Group the facts about each purchase in dictionaries, package the work into reusable functions, and save everything to a file so it survives between runs.

    1. Dictionaries: labelled data and totals by category
    2. Writing your own functions· checkpoint
    3. Saving and loading expenses with files
  4. 4.Making it robust and finishing the tracker

    Read and handle errors calmly, lean on Python's standard library, and assemble everything into a finished, tested program with a menu.

    1. Errors, tracebacks and debugging· checkpoint
    2. Modules and the standard library
    3. Finishing the expense tracker· checkpoint

Lesson 1

Installing Python 3 and running your first program

What you'll learn: how to install Python 3, check that it works, and run your first program from a file.

Meet Nadia and her expense tracker

Nadia has a feeling that her money disappears faster than it should, but her banking app only shows a long scroll of transactions. She wants something simpler: a small program where she types in what she bought and how much it cost, and it tells her where the money went. Over the next twelve lessons she is going to build exactly that, one piece at a time, in Python.

Python is a programming language: a precise way of writing instructions that a computer can follow. It reads almost like English, which makes it a favourite first language, and professionals use it for everything from websites to data analysis. Everything in this course works on Windows, macOS and Linux.

Installing Python 3

You need Python 3. The old Python 2 stopped receiving updates in 2020, and nothing in this course will run on it. Any recent version of Python 3 is fine; new versions arrive every October, and the basics you will learn here have not changed in years.

How you install it depends on your computer:

Your computerHow to installCommand to check it works
WindowsThe installer from the official Python website, or Python from the Microsoft Storepy --version or python --version
macOSThe installer from the official Python website (Homebrew also works if you already use it)python3 --version
LinuxUsually already installed; if not, your distribution's package managerpython3 --version

On Windows, if the installer shows a box labelled "Add python.exe to PATH", tick it. It lets your terminal find Python. On macOS, typing python3 before installing anything may pop up an offer to install Apple's developer tools; the official installer is the simpler route for a beginner.

To check, open a terminal. On Windows that is Terminal or Command Prompt from the Start menu; on macOS it is Terminal in Applications, then Utilities. Type the check command from the table and press Enter. You should see something like this:

Python 3.13.2

The exact numbers will differ. Anything starting with 3 means you are ready. If you see "command not found" or "is not recognized", the installation did not finish or the PATH box was not ticked; running the installer again usually fixes it.

Two ways to run Python

Python can run your instructions in two ways, and it helps to know both from the start.

The first is the interactive prompt. Type python3 on macOS or Linux, or py on Windows, and press Enter. You will see three arrows:

>>>

This is Python waiting for an instruction. Type 2 + 3 and press Enter, and it answers 5 straight away. Type print("Hello, Nadia") and it shows Hello, Nadia. When you are done, type exit() and press Enter.

The second way is a program file: a plain text file, ending in .py, that holds a list of instructions. Python reads the file from top to bottom and carries out each line in order.

The difference between these two is the idea that trips up most beginners, so here is an everyday comparison. The interactive prompt is like a pocket calculator: you press keys, get an answer, and when you switch it off, nothing is kept. A program file is like a recipe card: you write the steps down once, and anyone can follow the same card tomorrow and get the same result. Nadia's tracker needs to be a recipe card, because she wants to run it again every day.

Writing the first line of the tracker

You need somewhere to write the file. Python comes with a simple editor called IDLE on Windows and macOS (on Linux it may be a separate package). A free code editor such as Visual Studio Code also works well. What matters is that the file is saved as plain text with a name ending in .py. A word processor will not do, because it adds hidden formatting.

Make a folder called tracker somewhere easy to find, such as your Documents folder. Inside it, create a file called tracker.py and type this single line:

print("Nadia's expense tracker")

Save the file. Now, in the terminal, move into the folder with the cd command (short for "change directory"). If the folder is inside Documents, that is:

cd Documents/tracker

Then run the program:

python3 tracker.py

On Windows, use py tracker.py instead. Python reads the file and prints:

Nadia's expense tracker

That is a complete program. It is small, but every program you will ever write is run in exactly this way.

What that line actually says

print is a function: a named action that Python already knows how to do. The round brackets hold what you are giving it, and the text inside the quotation marks is the message. The quotes tell Python "this is text, not an instruction". Leave one out and Python stops with an error, which is normal; lesson 10 is about reading those errors calmly.

Try adding two more lines to the file, each on its own line with no spaces in front:

  • print("Track what you spend, one item at a time.")
  • print("Version 1")

Run it again and you will see three lines of output, in the same order as the file. Python always works from the top of the file down, one line after another, unless you tell it otherwise.

A note on how code appears in this course: each line of code is shown on its own, and when a program has several lines, each one is its own list item. Python cares about the spaces at the start of a line, so whenever a line needs to be indented, the lesson will say so in words.

Recap

  • Install Python 3 for your system and check it with python3 --version (or py --version on Windows).
  • The interactive prompt (>>>) is a calculator for quick experiments; a .py file is a recipe card you can run again.
  • Write programs in a plain text editor such as IDLE or VS Code, never a word processor.
  • Run a file with python3 tracker.py (or py tracker.py) from the folder that holds it.
  • Python runs a file from top to bottom, one line at a time.

Lesson 2

Values, variables and arithmetic

What you'll learn: how Python stores values in variables, which kinds of numbers it has, and how to do the arithmetic an expense tracker needs.

From a greeting to real numbers

At the end of lesson 1, Nadia's tracker.py printed a title and two lines of text. It did not track anything yet. Today she gives it her first three expenses from this morning: a coffee for 3.20, a lunch for 8.50 and a bus fare for 2.75. (The amounts work the same whatever your currency, so read them as pounds, dollars, euros or anything else.)

To work with those amounts, Python needs two things: values, the pieces of data themselves, and variables, the names that let you refer to them later.

Values and their types

Every value in Python has a type, which decides what you can do with it. You will meet four types constantly:

TypeWhat it holdsExamples
intWhole numbers3, 0, -12, 2026
floatNumbers with a decimal point3.20, 8.5, -0.75
strText (a "string" of characters)"coffee", "8.50"
boolTrue or falseTrue, False

Notice that "8.50" in quotes is a string, not a number. It looks like a price, but to Python it is just four characters of text. That difference will matter a great deal in lesson 3.

You can ask Python for a value's type at the interactive prompt. type(3.20) answers <class 'float'>, and type("coffee") answers <class 'str'>. You never need to declare a type yourself; Python works it out from how you wrote the value.

Variables: names for values

A variable is created with a single equals sign. Add these lines to tracker.py, below the print lines, each starting at the left edge:

  • coffee = 3.20
  • lunch = 8.50
  • bus = 2.75

Each line means "make the name on the left refer to the value on the right". After these three lines run, the word coffee stands for 3.20 anywhere later in the program.

The single equals sign is the hardest idea in this lesson, because it does not mean "is equal to" as it does in maths. Think of a variable as a sticky note with a name written on it. The line coffee = 3.20 sticks the note labelled "coffee" onto the value 3.20. If you later write coffee = 3.60, you peel the note off and stick it on 3.60 instead. The old value is not changed; the label just moves.

That is why this line, which would be nonsense in maths, is perfectly normal in Python:

total = total + 2.75

Python first works out the right-hand side using the current value of total, then moves the total label onto the result. If total was 11.70, it now refers to 14.45.

Naming rules

Variable names can use letters, digits and underscores, but cannot start with a digit or contain spaces. They are case-sensitive, so Lunch and lunch are two different names. Python programmers write longer names in lower case with underscores, a style called snake case: bus_fare, monthly_budget. Choose names that say what the value is. lunch is better than x, and future you will be grateful.

Arithmetic

Python handles arithmetic with familiar symbols, plus a few you may not have seen:

OperatorMeaningExampleResult
+Add8.50 + 2.7511.25
-Subtract50 - 14.4535.55
*Multiply3.20 * 516.0
/Divide7 / 23.5
//Divide, keep the whole part7 // 23
%Remainder after dividing7 % 21
**Power2 ** 38

Brackets work as they do in maths: (3.20 + 8.50) * 2 adds first, then doubles.

Now Nadia can add up her morning. Add these two lines to the file:

  • total = coffee + lunch + bus
  • print(total)

Run tracker.py again and, after the title lines, it prints 14.45.

A small surprise with decimals

Try this at the interactive prompt: 0.1 + 0.2. Python answers 0.30000000000000004. This is not a bug in your installation. Computers store most decimal numbers as very close binary approximations, and occasionally the tiny difference shows. Every mainstream programming language does the same.

For a personal tracker, the simple fix is to round when you display a result: round(0.1 + 0.2, 2) gives 0.3. In lesson 3 you will learn a neater way to show exactly two decimal places. (Software that handles other people's money usually stores amounts as whole numbers of cents or pence, or uses Python's decimal module, to avoid this entirely.)

Where the tracker stands

Nadia's file now has three print lines, three expense variables, a total and a final print. It adds up a fixed list of purchases, which is a start. The obvious problem is that she has to edit the file every time she buys something. Next lesson, the program will ask her instead.

Recap

  • Every value has a type: int, float, str or bool are the everyday ones.
  • = sticks a name onto a value; it is not a statement of equality.
  • total = total + 2.75 works out the right side first, then moves the label.
  • Use clear snake case names such as bus_fare.
  • Python's operators include // (whole division), % (remainder) and ** (power).
  • Decimal results can show tiny errors; round them when you display them.

This lesson ends with a 3-question checkpoint, graded in the app.

10 more lessons in this course

Start it in Akadyo to read on, take the checkpoints and keep your place, with a tutor beside every lesson.