Project: Your first Python file
This project checks that your tools work together: your terminal, your editor and Python. It is also the first time you write a program in a real editor and run it from a terminal, as you will for every project. If a step below is unfamiliar, the linked page explains it.
Before you start, make sure you have done these. If not, each one links to the page that walks through it:
- Learned the basics of the terminal: What a terminal is and Find your way around the terminal.
- Installed a terminal on your own computer and made your
python-projectsfolder (~/Projects/python-projects): Install your terminal. - Installed Python with uv: Install Python with uv.
- Installed VS Code and opened your
python-projectsfolder in it: Set up your editor.
Preview the program
Here is the program you will write. The box below is only a preview, so you can see how it behaves. Press Run and a box asks for your color. Running it here does not count as doing the project. The project is to get this program working on your own computer, in your own editor, as described below.
Do it on your computer
- In VS Code, create a new file named
my_color.pyin yourpython-projectsfolder. - Copy the code from the box above into
my_color.py. ReplaceYour Namewith your name and the date with the current date. - Save the file in VS Code (Ctrl+S on Windows, Cmd+S on Mac). The terminal runs the saved version, not what is on screen.
- Open your terminal and move into your
python-projectsfolder:cd ~/Projects/python-projects. - Check that the file arrived with
ls. You should seemy_color.pyin the list. - Run the program with
python my_color.py. It asks for your favorite color. Type one and press Enter.
Your terminal should look something like this (your color will differ):
~/Projects/python-projects $ ls
my_color.py
~/Projects/python-projects $ python my_color.py
Please enter your favorite color: blue
Your favorite color is blue.
If you can do this, your editor and Python are working and you are ready for the rest of the course.