programming · Level 2
Python: from first script to a useful automation
Install Python, learn the basics, then build, test and safely use a small tool that tidies and reports on a folder.

Start with the essentials
The short answer
Python is a free, general-purpose programming language that suits routine computer tasks. Install it from python.org, save a script as a plain text file and run it from a terminal. A safe first automation reads before it writes, defaults to a dry run, never deletes anything and has a simple test behind it before you point it at real files.
What you will learn
- You will be able to install Python, run a script and read its output and its error messages.
- You will be able to write short programs using variables, decisions, loops and functions.
- You will be able to read and write text and CSV files and handle errors without hiding them.
- You will have built, tested and safely run a small tool that sorts and reports on a folder.
- You will be able to review a script written by someone else, or by an AI assistant, before you run it.
Who it is for
Complete beginners to programming who want to automate something real. You should be comfortable saving files and willing to type commands into a terminal window. No earlier coding experience is needed.
Before you start
- None. You need a computer you can install free software on, and a willingness to type and run small programs. The Your first prompts workbook is helpful if you want to use an AI assistant alongside the exercises.
Read a sample · Chapter 02 of 06
Values, decisions and loops
Programs remember values, make decisions and repeat work. Learn these three and you can read most short scripts.
A variable is a name attached to a value, as in price = 2.5. Every value has a type that decides what you can do with it.
Scroll sideways to see every column.
| Type | Holds | Example |
|---|---|---|
str | Text | "tea" |
int | Whole numbers | 3 |
float | Decimal numbers | 2.5 |
bool | True or False | True |
list | An ordered collection | ["tea", "cake"] |
dict | Labels with values | {"tea": 2.5} |
3 is a number but "3" is text, and Python will not add the two: it stops with a TypeError rather than guess.
Decisions use if, elif and else; loops use for. Indentation shows what belongs inside, so keep it consistent. An f-string such as f"Total: {total:.2f}" puts a value in text, and .2f means two decimal places.
prices = {"tea": 2.5, "coffee": 3.0, "cake": 4.25}
order = ["tea", "cake", "cake", "juice"]
total = 0.0
for item in order:
if item in prices:
total = total + prices[item]
else:
print(f"No price for {item}, skipping it")
print(f"Total: {total:.2f}")No price for juice, skipping it
Total: 11.00Read it aloud: for each item, if we have a price add it, otherwise say so.
Try it yourself · Activity 02
15 minChange the order
Predict before you run, then check yourself.
- Save it as
order.py, predict the output, then run it. - Add
"coffee"to the order and predict again. - After the loop, take 10 per cent off if the total is above 10.
Which prediction was wrong, and why?
Worked answer
The first run prints No price for juice, skipping it, then Total: 11.00. With coffee it is 14.00. After the loop, if total > 10: with total = total * 0.9 indented beneath it gives Total: 12.60.
Keep learning
The complete workbook
This workbook takes a complete beginner from installing Python to a small, tested tool that sorts and reports on a folder of files. You will learn variables, decisions, loops, functions, files, CSV and error handling, then add a dry-run habit and a first automated test. You will also practise reading other people's code, and AI-written code, with a critical eye.
- 01Install Python and run a scriptIn the workbook · 1 exercise
Install Python, try one line, then run a saved script.
- 02Values, decisions and loopsRead here · 1 exercise
Programs remember values, make decisions and repeat work. Learn these three and you can read most short scripts.
- 03Functions, files and pathsIn the workbook · 1 exercise
Functions organise your work, and files and paths are how scripts touch the real world.
- 04Text, CSV and things going wrongIn the workbook · 1 exercise
Real data is messy, so learn to read files and to fail well.
- 05Build the folder tool, dry run firstIn the workbook · 1 exercise
Combine everything into one tool that sorts a folder's files by type and reports what it did.
- 06Test it, review it, know your limitsIn the workbook · 1 exercise
A tool you have not tested is a tool you are hoping about. Add a first test, then learn to read code you did not write.
Also inside: a 9-point checklist, a glossary of 12 terms and 10 questions and answers to test yourself. 6 hands-on exercises, each with a worked answer at the back where the workbook gives one.
No login, no card, no account. Before the download we ask you to follow Mickai (two quick links). Free to download and use for personal learning, study groups and inside your own team. Please do not resell the workbooks or republish them as your own. Link people to trust-agent.ai instead.
Test yourself
Questions and answers
Do I need maths or a computing background to learn Python?
Not to automate everyday tasks. If you can follow a recipe or a spreadsheet formula, you have enough to start. What you do need is patience with small errors, because everyone meets them, and the habit of reading error messages slowly.
Which version of Python should I install?
A current, supported one. The version status page on python.org lists which versions still receive fixes, and at the time of writing each is supported for five years. This workbook was tested on Python 3.12.10, and its examples use only the standard library.
My computer cannot find the python command. What now?
Try py on Windows or python3 on macOS and Linux. If neither works, repeat the installation using the current instructions on python.org and read any prompt about your PATH, the list of places your computer looks for programs.
How do I read an error message?
Start at the bottom. The last line of a traceback names the type of error and says what went wrong. The lines above show where in your code it happened. Read the message, find the line, and change one thing at a time.
What is a dry run and why should scripts default to one?
A dry run reports what a script would do without doing it. Defaulting to one means a mistake, a wrong folder or a misunderstood option costs you a printout instead of your files. The script acts only when you add a flag such as --apply.
Is it safe to run code that an AI assistant wrote?
Not automatically. Such code can look convincing and still be wrong. Read it, ask what it reads, changes and deletes, check for a dry run, try it on copies first and test it. Never paste passwords or other people's private data into a prompt.
Why write encoding and newline in open() calls?
Up to Python 3.14, the documentation says the default encoding depends on the platform, so naming utf-8 makes a script behave the same everywhere. For CSV files, the csv module's documentation says to open them with newline="" so line endings are handled correctly.
Do I need a test for a small script?
Not for a throwaway one. For anything that changes files, or that you will run again, yes. A test records what the script must never do, such as overwrite a file, and it tells you at once if a later edit breaks that promise.
Do I need to install extra packages?
Not for this workbook. It uses only the standard library: pathlib, csv, argparse and unittest all come with Python. Packages written by other people are code you did not write, so read about one and check it before you install it.
Does this workbook make me a software engineer?
No. It teaches the basics and one careful habit set. Professional engineering also involves design, version control, code review, security and long-term upkeep. Treat this as a solid first step and keep building small, safe tools.
When you have finished
Get your certificate of completion
Type your name and download a certificate for this workbook as a PDF, ready to print or to add to LinkedIn. It is made on your own device, so your name is never sent to us. It is a self-declared certificate, not an accredited qualification.
Learn the language
Key terms
- Script
- A plain text file of Python instructions that the interpreter runs from top to bottom.
- Interpreter
- The program, started with
pythonorpython3, that reads Python code and carries it out. - Variable
- A name attached to a value, such as
price = 2.5. - Type
- The kind of a value, such as text (
str), whole number (int), decimal (float),listordict. - Function
- A named, reusable piece of code that takes inputs and can return a result.
- Path
- The location of a file or folder. The
pathlibmodule handles paths for you.
6 of the workbook's 12 terms. The complete glossary is in the workbook.
Follow the evidence
Sources and checks
Facts last checked: .
Examples in this workbook were run on: Python 3.12.10 on Windows 11 (2026-09-26).
These workbooks use AI assistance. See how the workbooks are made.
- Using Python on WindowsPython Software Foundation
- Using Python on macOSPython Software Foundation
- Using Python on Unix platformsPython Software Foundation
- Download PythonPython Software Foundation
- Status of Python versionsPython Developer's Guide
- Using the Python interpreter (The Python Tutorial)Python Software Foundation
- Reading and writing files (The Python Tutorial)Python Software Foundation
- Errors and exceptions (The Python Tutorial)Python Software Foundation
- The Python TutorialPython Software Foundation
- Beginner's Guide to PythonPython Wiki
- Built-in functions (open, eval, exec)Python Software Foundation
- pathlib: object-oriented filesystem pathsPython Software Foundation
- csv: CSV file reading and writingPython Software Foundation
- sys: system-specific parameters and functionsPython Software Foundation
- argparse: parser for command-line optionsPython Software Foundation
- unittest: unit testing frameworkPython Software Foundation
- tempfile: temporary files and directoriesPython Software Foundation
- shutil: high-level file operationsPython Software Foundation
- subprocess: subprocess managementPython Software Foundation
Created by Mickarle Wagstaff-Irons - Micky Irons with the Mickai team. Published by Mickai LTD. Last updated 26 September 2026.
NextKeep going
Where to go next
Recommended for you
Your first prompts: how to ask AI for what you actually want
Learn to ask AI for what you actually want: the six parts of a good prompt, how to improve a reply, and how to build a personal prompt library. Free tools only.
Recommended for you
Build your first chatbot
Build a chatbot that behaves: model access, system prompt, history and context limits, guardrails, tone, a test set, logging and cost, on a no-code path or a code path.
Recommended for you
The loop harness: how AI agents actually run
How an agent harness runs a model in a loop: context, tools, permissions, budgets, stop conditions, logging and testing, with a minimal Python loop and a paper design exercise.