Installing Python and running your first program
Install Python on Windows, confirm from the terminal that it actually works, and run your first Python file on your own machine.
- 1Encounter
- 2Understand
- 3Worked
- 4Predict
- 5Apply
- 6Stretch
The problem we are solving
You want to learn Python. There are plenty of sites where you can type code into a browser — but nobody writes code in a browser at work. At work, Python is installed on your own machine, you open a terminal, you run commands, and you save files and execute them.
So we will work that way from day one. By the end of this mission you will have real Python on your computer, and you will have run a program with it.
By the end of this mission you can
- Install Python 3.12 on Windows
- Verify from the terminal that the installation actually works
- Write a
.pyfile and run it - Recognise and fix the single most common installation mistake
Prerequisites: none. This is the first mission.
Step 1 — Download Python
Go to python.org/downloads and use the large button to download the latest 3.12 release.
Do not install from the Microsoft Store. On Windows, typing python often opens the Store instead. The Store build runs in a restricted environment, which causes strange failures later when you install packages or write files next to your code. Use python.org.Step 2 — Tick one box during installation
When the installer opens, there is a small checkbox at the bottom of the very first screen:
[ ] Add python.exe to PATHTick it. This is the most important step in the mission.
PATH is the list Windows searches to decide which programs can be run from anywhere. Without it Python still installs, but typing python in a terminal gets you an error — Windows simply does not know where Python went.
Then press Install Now.
Step 3 — Verify
When the installer finishes, open a new terminal. Press Start, type powershell, and open it.
Opening a new terminal matters. Any terminal that was already running still remembers the old PATH and will not see the new installation.
Run:
python --versionYou should see something like:
Python 3.12.7The final number may differ — that is fine. As long as it says 3.12, you are set.
Step 4 — Your first program
Make a folder, say D:\python-lab. Create a file in it called hello.py containing:
language = "Python"
print("Hello from", language)
print("2 + 3 =", 2 + 3)Now move to that folder in the terminal and run the file:
cd D:\python-lab
python hello.pyOutput:
Hello from Python
2 + 3 = 5Your computer just ran a Python program. Not a browser, not a website — your own machine.
When it breaks
Typing python opens the Microsoft Store Python is not on PATH, so Windows runs its own shortcut instead. Run the installer again, choose Modify, and tick "Add python.exe to PATH".
python : The term 'python' is not recognized... Same cause, same fix. You can also check whether py --version works — py is the Windows Python launcher and works even when PATH does not.
python hello.py says can't open file You are in the wrong folder. Run dir and check that hello.py is listed. If it is not, cd to the right folder.
The file is actually named hello.py.txt Windows hides file extensions by default. In File Explorer turn on View → Show → File name extensions, then rename the file.
Step 4 of 6 — Predict
Check your understanding
What appears in the terminal when this file is run with python hello.py?
language = "Python"
print("Hello from", language)
print("2 + 3 =", 2 + 3)- AHello from Python 2 + 3 = 5
- BHello from language 2 + 3 = 5
- CHello from Python 2 + 3 = 2 + 3
- DHello from, Python 2 + 3 =, 5
You installed Python, but python --version errors in the terminal. What is the most likely cause?
- A"Add python.exe to PATH" was not ticked during installation
- BPython 3.12 does not run on Windows
- CYou must create a `.py` file first
- DPython does not work until the computer is restarted
One thing is missing compared with the mission's example. What happens when this file runs?
language = Python
print("Hello from", language)- AAn error — without quotes Python reads `Python` as a variable name, and no such variable exists
- BHello from Python
- CHello from language
- DHello from — followed by a blank
Answering needs an account
Sign in to check your answers
The questions are above, and working them out in your head is the part that matters. Sign in to see the answers, the explanations and the three-level hints.
Your turn
Change hello.py so that it prints your own name and shows the result of 7 * 6. Save it and run python hello.py again.
The output should look something like:
Hello from <your name>
7 * 6 = 42There is more in this mission
What you read above is the complete mission — nothing was cut out of it. Pro adds:
- What actually happens underneath — how Python runs this
- The full solution to the exercise, worked step by step
- Harder extra exercises
- The interview question on this topic, with a model answer
Step 6 of 6
Stretch — the chapter quiz
Ten questions from easy to hard. The last ones are difficult on purpose.
Sign in to take the quiz