feat(curriculum): add Python module for installation and running code locally (#67279)

Signed-off-by: Jessica Wilkins  <67210629+jdwilkin4@users.noreply.github.com>
Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com>
This commit is contained in:
Jessica Wilkins
2026-05-25 06:54:36 -07:00
committed by GitHub
parent 0f592912c8
commit 425837204a
13 changed files with 769 additions and 11 deletions
@@ -7,7 +7,7 @@ dashedName: how-do-you-install-configure-and-use-python-in-your-local-environmen
# --description--
In the last lesson, you learned what Python is and what you can do with it. Now, let's look into how you can set up Python on your local machine.
For all of the workshops and labs, you will be using freeCodeCamp's Python editor. But it is important to learn how to set up Python on your local machine.
The easiest way to install Python on Windows and Mac is to download the installer from the official Python website. We'll also go over running Python on Linux later in this lesson.
@@ -24,7 +24,7 @@ We'll go over how to install Python on a computer running macOS first:
You can verify the installation by opening up your terminal and running `python --version` or `python3 --version`.
You can also open the Python interpreter by running `python` or `python3` in the terminal.
You can also open the Python interpreter by running `python` or `python3` in the terminal. A Python interpreter is the program that reads Python code, translates it into instructions the computer understands and executes those instructions.
A <dfn>terminal</dfn> is a text-based interface that lets you interact with your computer by typing commands. Each operating system comes with a default terminal app. On macOS, you can use the Terminal app. On Windows, you can use Command Prompt or PowerShell. On Linux, each desktop environment has its own default terminal app, like GNOME Terminal or Konsole.
@@ -0,0 +1,175 @@
---
id: 69fd6b21fcaa14b089c27182
title: How to Run Python Scripts
challengeType: 19
dashedName: how-to-run-python-scripts
---
# --description--
In the previous lesson, you learned how to install Python on your local device. In this lesson, you will learn how to run Python code locally.
Before you can start building your Python scripts locally, you will need to install a code editor or IDE. IDE stands for Integrated Development Environment and it has features including a code editor, testing tools, a terminal and more.
One popular code editor that many developers use is VS Code. Visit `https://code.visualstudio.com/download` to download VS Code which supports Mac, Windows and Linux environments. This is the editor that will be used in this lesson.
Other common choices for Python development include the following:
- PyCharm
- Spyder
Once you have downloaded your editor, you will need to open it. Once it is opened, you will need to open a folder. You can click on the `File` menu option in the upper left hand corner and click on `Open Folder`. From there, you can choose or create a folder for your project. For extra practice outside of the lesson, you might want a folder named `python-projects`.
Once you have your folder set up, you can open the explorer which is the left sidebar in VS Code. Click on the `New File` icon which looks like a piece of paper with a plus icon over it. Then create a file called `main.py` and press enter. The `.py` is a file extension signalling this is a Python file.
Open up your `main.py` file and type the following code:
```py
print("Hello, world!")
```
To run this code, you have a few options. The first option is to click on the run button which looks like a play button located in the upper right hand corner. That will open a terminal and run your Python script there. You should see the text `"Hello, world!"`.
Another option is to open a terminal and manually run the program using:
```bash
python main.py
```
You must run this command from the folder where `main.py` is saved. For example, if `main.py` is inside a folder called `python-projects`, first use the following in the terminal:
```bash
cd python-projects
```
Then run:
```bash
python main.py
```
In some environments, especially on macOS and Linux systems where Python 2 and Python 3 are both installed, you may need to use `python3` instead of `python`. This is common when the `python` command either does not exist or points to an older version of Python.
```bash
python3 main.py
```
As you progress throughout the course, you should try the examples from the lessons locally and see the results. You should also try to come up with your own examples to test what you have learned from the lessons.
# --questions--
## --text--
Which of the following is NOT a commonly used editor or IDE for Python development?
## --answers--
Clang
---
VS Code
### --feedback--
Refer back to the beginning of the lesson for the correct answer.
---
Spyder
### --feedback--
Refer back to the beginning of the lesson for the correct answer.
---
PyCharm
### --feedback--
Refer back to the beginning of the lesson for the correct answer.
## --video-solution--
1
## --text--
What does IDE stand for?
## --answers--
Internal Development Environment
### --feedback--
Refer back to the beginning of the lesson for the correct answer.
---
Integrated Development Environment
---
Integrated Development Eval
### --feedback--
Refer back to the beginning of the lesson for the correct answer.
---
Integrated Deno Environment
### --feedback--
Refer back to the beginning of the lesson for the correct answer.
## --video-solution--
2
## --text--
Which of the following is the correct command to use if you want to run a Python script in the terminal?
## --answers--
```bash
pip main.py
```
### --feedback--
Refer to the end of the lesson for the answer.
---
```bash
pyrun main.py
```
### --feedback--
Refer to the end of the lesson for the answer.
---
```bash
python main.py
```
---
```bash
piode main.py
```
### --feedback--
Refer to the end of the lesson for the answer.
## --video-solution--
3
@@ -0,0 +1,179 @@
---
id: 69fd75321df075656f836fff
title: How to Use the Python Interactive Shell
challengeType: 19
dashedName: how-to-use-the-python-interactive-shell
---
# --description--
In the previous lesson, you learned how to run Python scripts locally. But there might be times where you don't want to create full Python programs and just need to test out some Python code. This is where the Python interactive shell comes in.
But first, let's review what a terminal is.
A terminal is a text-based interface that lets you interact with your computer by typing commands. Each operating system comes with a default terminal app. On macOS, you can use the Terminal app. On Windows, you can use Command Prompt or PowerShell. On Linux, each desktop environment has its own default terminal app, like GNOME Terminal or Konsole.
Open up a terminal app and type in `python` and press `Enter`. This will start a Python interactive shell. An interactive shell is a program that lets you type commands one at a time and see the results.
When you start a new session, you might see this type of output initially:
```bash
Python 3.12.2 (main, Mar 21 2024, 22:48:26) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
```
The `>>>` symbol means Python is waiting for you to type a command. Try printing `"Hello, world!"` to the terminal:
```bash
print("Hello, world!")
```
You should see the text appear like this:
```bash
>>> print("Hello, world!")
Hello, world!
```
After the text is printed, Python goes back to the following:
```bash
>>>
```
This means you can type in another command.
The Python interpreter is following what is known as the Read, Evaluate, Print, Loop cycle. Or REPL for short. Whenever you type in commands, the interpreter will read the input, evaluate it, print the result and loop back to show the `>>>` so you can type more commands.
What happens if you try to type in an invalid command like this?
```bash
>>> something random
```
Well, the Python interpreter will still follow the same REPL process. In this case, you will get an error message:
```bash
>>> something random
File "<stdin>", line 1
something random
^^^^^^
SyntaxError: invalid syntax
```
If you want to leave the interactive shell you can type `exit()` or press `Ctrl + D` for (Mac/Linux) or `Ctrl + Z + Enter` for (Windows).
Using Python's interactive shell is great for small experiments with code or basic exploration. While you are going through the remaining lessons in the course, you can type in some of the new methods you learned inside an interactive shell.
If you are planning to work with longer programs or working across multiple files, then it is better to work in a code editor or IDE.
# --questions--
## --text--
What is an interactive shell?
## --answers--
A program used to format Python code.
### --feedback--
Refer back to the beginning for the correct answer.
---
A program that lets you type commands one at a time and see the results.
---
A program used to lint Python code.
### --feedback--
Refer back to the beginning for the correct answer.
---
A program that lets you download popular Python libraries.
### --feedback--
Refer back to the beginning for the correct answer.
## --video-solution--
2
## --text--
What does REPL stand for?
## --answers--
Run, Execute, Process, Launch
### --feedback--
Refer back to the end for the correct answer.
---
Read, Execute, Print, Load
### --feedback--
Refer back to the end for the correct answer.
---
Read, Evaluate, Print, Loop
---
Read, Enter, Parse, Log
### --feedback--
Refer back to the end for the correct answer.
## --video-solution--
3
## --text--
Which of the following is a correct way to leave an interactive shell?
## --answers--
Type `exit()` in the terminal.
---
Type `stop()` in the terminal.
### --feedback--
Refer back to the end for the correct answer.
---
Type `end()` in the terminal.
### --feedback--
Refer back to the end for the correct answer.
---
Type `terminate()` in the terminal.
### --feedback--
Refer back to the end for the correct answer.
## --video-solution--
1
@@ -0,0 +1,234 @@
---
id: 69fd84e01123960e15bb8455
title: Python Installation Quiz
challengeType: 8
dashedName: quiz-python-installation
---
# --description--
To pass the quiz, you must correctly answer at least 9 of the 10 questions below.
# --quizzes--
## --quiz--
### --question--
#### --text--
Where is the best place to download Python for Windows, Mac, and Linux?
#### --distractors--
From GitHub repositories
---
From the npm package manager
---
From pip manager
#### --answer--
From the official Python website
### --question--
#### --text--
What is a terminal in the context of programming?
#### --distractors--
A graphical tool for designing apps.
---
A tool for linting and formatting your code.
---
A Python code editor with autocomplete.
#### --answer--
A text-based interface for running commands.
### --question--
#### --text--
What does IDE stand for?
#### --distractors--
Internet Development Engine
---
Integrated DevOps Environment
---
Internal Debugging Executor
#### --answer--
Integrated Development Environment
### --question--
#### --text--
Which of the following are popular IDEs or code editors for Python?
#### --distractors--
JetBrains, CLion, WindSurf
---
Photoshop, Illustrator, Figma
---
Clang, Pip, Deno
#### --answer--
VS Code, PyCharm, Spyder
### --question--
#### --text--
How do you typically run a Python file named `main.py` from the terminal?
#### --distractors--
`run main.py`
---
`pip main.py`
---
`execute main.py python`
#### --answer--
`python main.py`
### --question--
#### --text--
What is an interactive shell?
#### --distractors--
A program that audits your code for errors.
---
A program that runs tests against your code.
---
A program to lint your code.
#### --answer--
A program that lets you type commands one at a time and see the results.
### --question--
#### --text--
How do you start the Python interactive shell from the terminal?
#### --distractors--
Type `node python` and press `Enter`.
---
Type `run python` and press `Enter`.
---
Type `start python shell` and press `Enter`.
#### --answer--
Type `python` and press `Enter`.
### --question--
#### --text--
What does the `>>>` symbol mean in the Python interactive shell?
#### --distractors--
Python has stopped running.
---
Python is testing your code.
---
Python is installing packages.
#### --answer--
Python is waiting for the user input text.
### --question--
#### --text--
What does REPL stand for?
#### --distractors--
Run Execute Process Loop
---
Read Evaluate Print List
---
Runtime Execution Programming Language
#### --answer--
Read Evaluate Print Loop
### --question--
#### --text--
What happens when you run `print("Hello, world!")` in the Python interactive shell?
#### --distractors--
It prints `"Hello, world!"` on loop until the user stops it.
---
It creates a file and prints `"Hello, world!"` in the terminal.
---
It throws an error because that is not valid Python code.
#### --answer--
It prints `"Hello, world!"` in the terminal.
@@ -12,10 +12,6 @@ dashedName: review-python-basics
- **Introduction**: Python is a general-purpose programming language known for its simplicity and ease of use. Python is used in many fields like data science and machine learning, web development, scripting and automation, embedded systems and IoT, and much more.
- **Common Use Cases**: Python is used in data science, machine learning, web development, cybersecurity, automation and microcomputers like the Raspberry Pi and MicroPython-compatible boards.
## Python in Your Local Environment
- **Installation**: The best way to install Python on Windows, Mac, and Linux is to download the installer from the official Python website (`https://www.python.org/`).
## Variables
- **Declaring Variables**: To declare a variable, you start with the variable name followed by the assignment operator (`=`) and then the value. This can be a number, string, boolean, etc. Here are some examples:
@@ -0,0 +1,63 @@
---
id: 69fd80a1798f22441459a70f
title: Python Installation Review
challengeType: 31
dashedName: review-python-installation
---
# --description--
## Python in Your Local Environment
- **Installation**: The best way to install Python on Windows, Mac, and Linux is to download the installer from the official Python website (`https://www.python.org/`).
- **Terminal**: A text-based interface that lets you interact with your computer by typing commands. Each operating system comes with a default terminal app. On macOS, you can use the Terminal app. On Windows, you can use Command Prompt or PowerShell. On Linux, each desktop environment has its own default terminal app, like GNOME Terminal or Konsole.
- **IDE**: IDE stands for Integrated Development Environment and it has features including a code editor, testing tools, a terminal and more.
- **Popular Code Editors and IDEs for Python**: VS Code, PyCharm, and Spyder
- **Running Code Locally**: To run Python code, you have a few options. The first option is to click on the run button in VS Code which looks like a play button located in the upper right hand corner. That will open a terminal and run your Python script there.
Another option is to open a terminal and manually run the program. Here is an example to run a program called `main.py`:
```bash
python main.py
```
You must run this command from the folder where `main.py` is saved. For example, if `main.py` is inside a folder called `python-projects`, first use the following in the terminal:
```bash
cd python-projects
```
Then run:
```bash
python main.py
```
## Using the Python Interactive Shell
- **Definition**: An interactive shell is a program that lets you type commands one at a time and see the results. Open up a terminal app and type in `python` and press `Enter`. This will start a Python interactive shell. The `>>>` symbol means Python is waiting for you to type a command. Try printing `"Hello, world!"` to the terminal:
```bash
print("Hello, world!")
```
You should see the text appear like this:
```bash
>>> print("Hello, world!")
Hello, world!
```
After the text is printed, Python goes back to the following:
```bash
>>>
```
This means you can type in another command.
- **Read, Evaluate, Print, Loop cycle (REPL)**: Whenever you type in commands, the interpreter will read the input, evaluate it, print the result and loop back to show the `>>>` so you can type more commands.
# --assignment--
Review the Python Installation topics and concepts.
@@ -15,6 +15,53 @@ dashedName: review-python
## Python in Your Local Environment
- **Installation**: The best way to install Python on Windows, Mac, and Linux is to download the installer from the official Python website (`https://www.python.org/`).
- **Terminal**: A text-based interface that lets you interact with your computer by typing commands. Each operating system comes with a default terminal app. On macOS, you can use the Terminal app. On Windows, you can use Command Prompt or PowerShell. On Linux, each desktop environment has its own default terminal app, like GNOME Terminal or Konsole.
- **IDE**: IDE stands for Integrated Development Environment and it has features including a code editor, testing tools, a terminal and more.
- **Popular Code Editors and IDEs for Python**: VS Code, PyCharm, and Spyder
- **Running Code Locally**: To run Python code, you have a few options. The first option is to click on the run button in VS Code which looks like a play button located in the upper right hand corner. That will open a terminal and run your Python script there.
Another option is to open a terminal and manually run the program. Here is an example to run a program called `main.py`:
```bash
python main.py
```
You must run this command from the folder where `main.py` is saved. For example, if `main.py` is inside a folder called `python-projects`, first use the following in the terminal:
```bash
cd python-projects
```
Then run:
```bash
python main.py
```
## Using the Python Interactive Shell
- **Definition**: An interactive shell is a program that lets you type commands one at a time and see the results. Open up a terminal app and type in `python` and press `Enter`. This will start a Python interactive shell. The `>>>` symbol means Python is waiting for you to type a command. Try printing `"Hello, world!"` to the terminal:
```bash
print("Hello, world!")
```
You should see the text appear like this:
```bash
>>> print("Hello, world!")
Hello, world!
```
After the text is printed, Python goes back to the following:
```bash
>>>
```
This means you can type in another command.
- **Read, Evaluate, Print, Loop cycle (REPL)**: Whenever you type in commands, the interpreter will read the input, evaluate it, print the result and loop back to show the `>>>` so you can type more commands.
## Variables