You do not need to know another programming language. You do not need to be good at maths. You need a computer, a little patience, and permission to write something that fails on the first attempt. Permission granted.
Our first project is a tiny cinema called The Slightly Haunted Cinema. Its computer will eventually sell tickets. Today, its entire job is to announce that the doors are open. Management has agreed this is a reasonable first day.
By the end: you can save a Python file, run it, explain its output, and repair a syntax error. Allow about 25–40 minutes, including setup. Reading without running the code will be much quicker, and much less useful.
What are we actually writing?
A program is a set of instructions for a computer. The text you write is source code. Python is the language we use to express those instructions; the Python interpreter is the program that executes them.
An editor lets you write and save code. It does not become Python just because you type Python into it. Think of the editor as the notebook and the interpreter as the person following the recipe, except the person refuses to guess what you meant by “a reasonable amount of flour.”
We will use IDLE, Python’s small editor and interactive shell. It keeps setup modest and gives us a place to type code and see results. If you already have another working Python editor, you can use it.
Set up a place to work
Use a supported, stable Python 3 release from the official Python downloads page. Avoid releases labelled alpha, beta, or release candidate for this course. These lessons use basic Python 3 features; there is no particular patch number to chase.
- Windows: follow the site’s Windows installation instructions. Once Python is installed, search the Start menu for IDLE. If it is not listed, open PowerShell, type
py -m idlelib, and press Enter. This is a terminal command, not Python code. Ifpyis not recognised, revisit the official Windows setup guide. - macOS: use the macOS installer from python.org, then open IDLE from the installed Python folder in Applications. You can also launch it from Terminal with
python3 -m idlelib. - Linux: use your distribution’s Python 3 and IDLE packages. IDLE may be a separate package; the official Unix installation notes list common options. After installation,
python3 -m idleliblaunches it from a terminal.
If you see an error mentioning idlelib or tkinter, your installation is missing an optional component needed by IDLE. Use the instructions for your Python distribution rather than trying random installation commands.
Create a folder called python-course in your Documents folder. This is where our .py files will live. The .py ending identifies a Python source file.
Run your first saved program
In IDLE, select File → New File. A blank editor window opens. Type these three lines, including the quotes and parentheses:
print("Welcome to The Slightly Haunted Cinema!")
print("Tonight: The Return of the Missing Semicolon")
print("Doors open at 19:00.")
Save the file as cinema.py inside python-course. In that editor window, select Run → Run Module. IDLE runs the saved code and displays the result in its Shell window:
Welcome to The Slightly Haunted Cinema!
Tonight: The Return of the Missing Semicolon
Doors open at 19:00.
IDLE may also display a restart banner and a >>> prompt. Those belong to the environment, not to our program’s output. Do not copy them into your file.
Change 19:00 to 18:30, save, and run again. If the old time still appears, check that you saved and ran the file you edited. This edit → save → run → inspect cycle is programming in miniature.
Read one line carefully
Take print("Doors open at 19:00."):
| Piece | Meaning |
|---|---|
print | The name of a built-in function that displays values. |
( and ) | Call the function with the information inside. |
"Doors open at 19:00." | A string: a value containing text. |
A function performs a named task. Calling it means asking it to do that task. The value we supply is an argument. You can use a built-in function before learning to write your own, just as you can press a lift button before designing a lift.
The quotes mark where the text begins and ends; print() does not display them. Use ordinary straight quotes in code, not a word processor’s curly quotation marks. Single quotes also work: print('Hello'). Choose a style and keep it consistent.
For these simple statements, Python runs the lines in order. Each print() call ends its output with a new line by default. Blank lines in the source make code easier to read but do not themselves print blank lines. print() with nothing between its parentheses does.
Break it on purpose
In a separate file called broken.py, try this deliberately incomplete line:
print("The popcorn is ready."
It is missing the closing ). Python reports a SyntaxError: the code does not follow the language’s writing rules. IDLE may highlight the problem in the editor; the exact wording depends on your Python version.
Add the missing parenthesis and run again. That is a complete debugging cycle: reproduce the problem, locate it, make one change, check the result. No ritual sacrifice to the laptop required.
When a program fails, look for the error type, the file and line mentioned, and the nearby code. An error location is a clue, not a guarantee that the mistake began on precisely that character.
Your turn: announce a screening
Create announcement.py. It should print four lines:
- A cinema name of your choice.
- A made-up film title.
- A blank line.
Please do not feed the projector.
Before you run it, predict how many print() calls you need. Then change the order of two calls and predict the new output.
Show one solution
print("The Slightly Haunted Cinema")
print("Attack of the Very Small Tomatoes")
print()
print("Please do not feed the projector.")
Four calls produce four lines, including the empty one. The output order follows the call order. Your film title can be different; the goal is to control the output intentionally.
Before moving on
Can you explain why the quotes disappear from the output? Can you close your file, reopen it, change a line, and run it again? Can you fix a missing parenthesis without replacing the whole program?
If yes, you have the essential workflow. Next, we will give our cinema some values to remember and some arithmetic to do.
Optional reference: Python’s IDLE guide. You do not need to read the whole manual before lesson two.