This repository contains exercises for the Udemy course The Python Programmer designed and maintained by Shehab Abdel-Salam.
The course is divided into chapters, each containing exercises and tests. The exercises are designed to help students practice Python programming concepts, while the tests are used to verify the correctness of their solutions.
The repository has the following structure:
├── chapters/
│ ├── chapter1/
│ │ ├── exercises/
│ │ │ ├── exercise_ch1_01.py
│ │ │ ├── exercise_ch1_02.py
│ │ │ └── ...
│ │ └── tests/
│ │ └── test_ch01.py
│ ├── chapter2/
│ │ ├── exercises/
│ │ │ ├── exercise_ch2_01.py
│ │ │ ├── exercise_ch2_02.py
│ │ │ └── ...
│ │ └── tests/
│ │ └── test_ch02.py
│ └── ...
├── ninja_challenges/
│ ├── exercises/
│ │ ├── challenge_01.py
│ │ ├── challenge_02.py
│ │ └── ...
│ └── tests/
│ └── test_ninja_challenges.py
The chapters
directory contains subdirectories for each chapter in the course. Each chapter directory contains an exercises
directory for the exercises, a tests
directory for the tests, and a main.py
file for testing your code.
The ninja_challenges
directory contains additional challenges for you to practice more once you complete the course. It also has an exercises
directory for the challenges and a tests
directory for the tests.
Before you begin, ensure you have the following installed on your machine:
- Python 3.12 or higher
pip
package managerpytest
testing framework
To check if you have Python installed, run the following command in your terminal:
python --version
If you get a command not found: python
, you can download and install Python from the official website: Python Downloads
To check if you have pip
installed, run the following command in your terminal:
pip --version
If you get a command not found: pip
, you can install pip
by following the instructions on the official website: Installing pip
To install pytest
, run the following command in your terminal:
pip install pytest
This will install the latest version of pytest
on your machine.
This repository was last tested with
pytest
version 8.3.2.
Note that you may need to use
pip3
instead ofpip
depending on your Python installation.
First, make sure to clone the repository to your local machine using the following command:
git clone https://github.com/shehab-as/The-Python-Programmer.git
Afterwards, navigate to the repository directory:
cd The-Python-Programmer/
-
Navigate to the chapter you are working on:
cd chapters/chapter01_intro
-
Edit the main.py file to write your solution or test your code.
python main.py
-
Write your solution in the corresponding exercise file. For example, if you are working on exercise 1 in chapter 1, you should write your solution in the
exercise_00.py
file. -
Run the test to verify the correctness of your solution.
Note: Always use the
-k
flag to run a specific test.pytest -k e00
Click to see the following output if the test fails:
tests/test_ch01.py:5: AssertionError =========================================== short test summary info =========================================== FAILED tests/test_ch01.py::test_e00 - AssertionError: assert 'I am ready to learn ______!' == 'I am ready to learn Python!' =========================================== 1 failed in 0.01s ===========================================
Click to see the following output if the test passes:
tests/test_ch_01.py . [100%] =========================================== 1 passed in 0.01s =============================================
Optional: You can run all the tests for the chapter you are currently working on:
pytest tests/
-
If the test fails, you will see an error message indicating the reason for the failure. Fix the issue in your code and run the test again.
-
Repeat steps 2-5 for each exercise in the chapter.
-
Once you have completed all the exercises in the chapter, you can move on to the next chapter and repeat the process.
cd ../chapter02_variables
-
Navigate to the ninja challenges directory:
cd ninja_challenges/
-
Edit the main.py file to write your solution or test your code.
python main.py
-
Run the test to verify the correctness of your solution.
Note: Always use the
-k
flag to run a specific test.pytest -k challenge_01
If you have any questions or would like to report an issue, you can click here to raise an issue on the repository and I'll make sure to review them as soon as possible.
Happy coding! 🐍