// python · beginner
Your First Python Program: Install, Write and Run It
A step-by-step beginner guide to installing Python on Windows or Mac, writing your first script and fixing the errors almost everyone hits on day one.
Python is one of the friendliest languages to start with. Its code reads almost like English, it’s free, and it runs on every major computer. By the end of this guide you’ll have Python installed, you’ll have written a small program, and you’ll know how to fix the three errors that trip up nearly every beginner.
Step 1: Install Python
On Windows
- Go to python.org/downloads and click the big yellow Download Python button.
- Open the installer. On the first screen, tick “Add python.exe to PATH” at the bottom. This is the step people most often miss, and it’s what lets you run Python from the terminal.
- Click Install Now and wait for it to finish.
On a Mac
Download the macOS installer from the same page and run it. On a Mac, the command is usually python3 rather than python, so use python3 wherever this guide says python.
Step 2: Check it worked
Open a terminal: Command Prompt on Windows (press Start and type cmd) or Terminal on a Mac. Type:
python --version
You should see something like Python 3.13.0. The exact number doesn’t matter, as long as it starts with 3.
Tip: If Windows says “python is not recognized”, the PATH box wasn’t ticked. Run the installer again, choose Modify, and make sure Add Python to environment variables is ticked.
Step 3: Try the interactive shell
Type python on its own and press Enter. You’ll see >>>, which is Python waiting for you. Try a few lines:
>>> 2 + 3
5
>>> "code" * 3
'codecodecode'
>>> print("Hello!")
Hello!
The shell is perfect for quick experiments. Type exit() to leave it.
Step 4: Write a real program
For anything longer than a line or two, you’ll write your code in a file. Create a new folder called coderunner, then create a file inside it called hello.py. You can use Notepad, but a code editor such as VS Code is much nicer (see our VS Code setup guide).
Put this in the file:
# hello.py - my first Python program
name = input("What is your name? ")
print("Hello, " + name + "!")
print("Welcome to CodeRunner.")
Line by line:
- Lines starting with
#are comments. Python ignores them; they’re notes for humans. input()shows a question and waits for the user to type an answer. Whatever they type is stored inname.print()shows text on the screen. The+joins pieces of text together.
Step 5: Run it
In your terminal, move into your folder and run the file:
cd coderunner
python hello.py
You’ll see:
What is your name? Sam
Hello, Sam!
Welcome to CodeRunner.
Congratulations, that’s a working program! It takes input, does something with it, and produces output, which is what every program does, however big.
The three errors everyone meets
1. “No such file or directory”
python: can't open file 'hello.py': [Errno 2] No such file or directory
Your terminal is in a different folder from your file. Use cd to move into the folder that holds hello.py, or type dir (Windows) / ls (Mac) to see where you are.
2. SyntaxError
print("Hello)
^
SyntaxError: unterminated string literal
Python couldn’t understand a line. Here a closing quote is missing. The ^ points at roughly where Python got confused, so look at that spot and the line just above it.
3. IndentationError
IndentationError: unexpected indent
In Python, spaces at the start of a line mean something. Don’t add spaces before a line unless it belongs inside a block (you’ll meet blocks in the if statements and loops guide).
Try it yourself
Change hello.py so it also asks for the user’s favourite food and prints a sentence using both answers. Then run it again. Small changes like this are how coding really sinks in.
What’s next
Now that Python runs on your computer, learn how it stores information in Python Variables and Data Types.