diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 449dc00162e..bd5ee9ebb77 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -6342,6 +6342,7 @@ }, "modules": { "python-basics": "Python Basics", + "python-installation": "Install Python", "python-loops-and-sequences": "Loops and Sequences", "python-dictionaries-and-sets": "Dictionaries and Sets", "lab-user-configuration-manager": "Build a User Configuration Manager", @@ -6363,7 +6364,7 @@ "lecture-introduction-to-python": { "title": "Introduction to Python", "intro": [ - "In these lessons, you will learn what Python is and how to set up your development environment." + "In these lessons, you will learn what Python is and common uses in the industry." ] }, "lecture-understanding-variables-and-data-types": { @@ -6455,6 +6456,24 @@ "Test what you've learned about Python basics with this quiz." ] }, + "lecture-python-installation": { + "title": "Installing Python and Running Code Locally", + "intro": [ + "In these lessons, you will learn how to install Python on your local device and run code locally." + ] + }, + "review-python-installation": { + "title": "Python Installation Review", + "intro": [ + "Before you are quizzed on working with Python locally, you should review the concepts covered in the lessons." + ] + }, + "quiz-python-installation": { + "title": "Python Installation Quiz", + "intro": [ + "Test what you've learned about installing Python locally with this quiz." + ] + }, "lecture-working-with-loops-and-sequences": { "title": "Working with Loops and Sequences", "intro": [ diff --git a/curriculum/challenges/english/blocks/lecture-introduction-to-python/67fe8567f141d632afaeb71b.md b/curriculum/challenges/english/blocks/lecture-python-installation/67fe8567f141d632afaeb71b.md similarity index 93% rename from curriculum/challenges/english/blocks/lecture-introduction-to-python/67fe8567f141d632afaeb71b.md rename to curriculum/challenges/english/blocks/lecture-python-installation/67fe8567f141d632afaeb71b.md index 491a7d5528e..a00859d8b7e 100644 --- a/curriculum/challenges/english/blocks/lecture-introduction-to-python/67fe8567f141d632afaeb71b.md +++ b/curriculum/challenges/english/blocks/lecture-python-installation/67fe8567f141d632afaeb71b.md @@ -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 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. diff --git a/curriculum/challenges/english/blocks/lecture-python-installation/69fd6b21fcaa14b089c27182.md b/curriculum/challenges/english/blocks/lecture-python-installation/69fd6b21fcaa14b089c27182.md new file mode 100644 index 00000000000..90bfc418443 --- /dev/null +++ b/curriculum/challenges/english/blocks/lecture-python-installation/69fd6b21fcaa14b089c27182.md @@ -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 diff --git a/curriculum/challenges/english/blocks/lecture-python-installation/69fd75321df075656f836fff.md b/curriculum/challenges/english/blocks/lecture-python-installation/69fd75321df075656f836fff.md new file mode 100644 index 00000000000..05f42e36099 --- /dev/null +++ b/curriculum/challenges/english/blocks/lecture-python-installation/69fd75321df075656f836fff.md @@ -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 "", 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 diff --git a/curriculum/challenges/english/blocks/quiz-python-installation/69fd84e01123960e15bb8455.md b/curriculum/challenges/english/blocks/quiz-python-installation/69fd84e01123960e15bb8455.md new file mode 100644 index 00000000000..ad7f3e8d717 --- /dev/null +++ b/curriculum/challenges/english/blocks/quiz-python-installation/69fd84e01123960e15bb8455.md @@ -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. diff --git a/curriculum/challenges/english/blocks/review-python-basics/67f39b40deaec81a3e40e0c5.md b/curriculum/challenges/english/blocks/review-python-basics/67f39b40deaec81a3e40e0c5.md index 3853b5659f2..e7562e1d72f 100644 --- a/curriculum/challenges/english/blocks/review-python-basics/67f39b40deaec81a3e40e0c5.md +++ b/curriculum/challenges/english/blocks/review-python-basics/67f39b40deaec81a3e40e0c5.md @@ -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: diff --git a/curriculum/challenges/english/blocks/review-python-installation/69fd80a1798f22441459a70f.md b/curriculum/challenges/english/blocks/review-python-installation/69fd80a1798f22441459a70f.md new file mode 100644 index 00000000000..350fa99abd0 --- /dev/null +++ b/curriculum/challenges/english/blocks/review-python-installation/69fd80a1798f22441459a70f.md @@ -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. diff --git a/curriculum/challenges/english/blocks/review-python/67f39e391c9b373069def02c.md b/curriculum/challenges/english/blocks/review-python/67f39e391c9b373069def02c.md index 1f497efb8a2..087a25b2aa0 100644 --- a/curriculum/challenges/english/blocks/review-python/67f39e391c9b373069def02c.md +++ b/curriculum/challenges/english/blocks/review-python/67f39e391c9b373069def02c.md @@ -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 diff --git a/curriculum/structure/blocks/lecture-introduction-to-python.json b/curriculum/structure/blocks/lecture-introduction-to-python.json index 6a34c809ae8..4915f6f7da3 100644 --- a/curriculum/structure/blocks/lecture-introduction-to-python.json +++ b/curriculum/structure/blocks/lecture-introduction-to-python.json @@ -7,10 +7,6 @@ { "id": "67fe81c9c6fd3714343a45ad", "title": "What Is Python and What Are Some Common Uses in the Industry?" - }, - { - "id": "67fe8567f141d632afaeb71b", - "title": "How Do You Install, Configure and Use Python in Your Local Environment?" } ], "helpCategory": "Python" diff --git a/curriculum/structure/blocks/lecture-python-installation.json b/curriculum/structure/blocks/lecture-python-installation.json new file mode 100644 index 00000000000..98cb5493426 --- /dev/null +++ b/curriculum/structure/blocks/lecture-python-installation.json @@ -0,0 +1,21 @@ +{ + "isUpcomingChange": false, + "dashedName": "lecture-python-installation", + "helpCategory": "Python", + "blockLayout": "challenge-list", + "blockLabel": "lecture", + "challengeOrder": [ + { + "id": "67fe8567f141d632afaeb71b", + "title": "How Do You Install, Configure and Use Python in Your Local Environment?" + }, + { + "id": "69fd6b21fcaa14b089c27182", + "title": "How to Run Python Scripts" + }, + { + "id": "69fd75321df075656f836fff", + "title": "How to Use the Python Interactive Shell" + } + ] +} diff --git a/curriculum/structure/blocks/quiz-python-installation.json b/curriculum/structure/blocks/quiz-python-installation.json new file mode 100644 index 00000000000..9dd419bf1b1 --- /dev/null +++ b/curriculum/structure/blocks/quiz-python-installation.json @@ -0,0 +1,10 @@ +{ + "isUpcomingChange": false, + "blockLayout": "link", + "blockLabel": "quiz", + "dashedName": "quiz-python-installation", + "helpCategory": "Python", + "challengeOrder": [ + { "id": "69fd84e01123960e15bb8455", "title": "Python Installation Quiz" } + ] +} diff --git a/curriculum/structure/blocks/review-python-installation.json b/curriculum/structure/blocks/review-python-installation.json new file mode 100644 index 00000000000..28ab128f127 --- /dev/null +++ b/curriculum/structure/blocks/review-python-installation.json @@ -0,0 +1,10 @@ +{ + "isUpcomingChange": false, + "dashedName": "review-python-installation", + "helpCategory": "Python", + "blockLayout": "link", + "blockLabel": "review", + "challengeOrder": [ + { "id": "69fd80a1798f22441459a70f", "title": "Python Installation Review" } + ] +} diff --git a/curriculum/structure/superblocks/python-v9.json b/curriculum/structure/superblocks/python-v9.json index b3efa8fb4ec..4e73373bb2e 100644 --- a/curriculum/structure/superblocks/python-v9.json +++ b/curriculum/structure/superblocks/python-v9.json @@ -24,6 +24,14 @@ "quiz-python-basics" ] }, + { + "dashedName": "python-installation", + "blocks": [ + "lecture-python-installation", + "review-python-installation", + "quiz-python-installation" + ] + }, { "dashedName": "python-loops-and-sequences", "blocks": [