Week 10 of 107 to 8 hours5 exercises
Week 10: Put it together: a project and what comes next
Combine everything in a small grade-book program, test it with assert, and learn how to run Python on your own computer and where to go next.
By the end of this week you can
- Plan a small program as a few functions
- Test code with assert
- Run Python files on your own computer, with pip and venv
- Choose a path after this course
Plan before you type
A beginner's biggest jump is going from small exercises to a whole program. The trick is to split the job into small functions, each of which you can test on its own, then connect them.
For our project, a class gradebook: it stores marks for students, works out each student's average and grade, and reports the top scorer. Write down the pieces first: add_marks(), average(), grade_for(), and top_student(). Build them one at a time and run the code after each step.
Each function does one thing, so it is easy to test and reuse.
The full grade-book program
Here is the project assembled as a class. Read it once slowly, then change it: add a method that removes a student, or one that lists everyone who passed with at least 50 on average. Making your own changes is the real exercise.
*scores lets add_marks accept any number of marks in one call.
Test your code with assert
An assert line states something that must be true and stops with an error if it is not. A handful of asserts under your functions is a simple safety net: run them after every change, and you will notice at once if you broke something. Bigger projects use tools such as pytest, which work in the same spirit.
No output from an assert means it passed.
Running Python on your own computer
This page runs Python for you, but real projects live on your computer. Steps: install Python from python.org (tick the option that adds it to PATH on Windows), save your code in a file such as hello.py and run it with python hello.py (python3 on Mac and Linux). A code editor such as VS Code makes this comfortable.
pip installs extra packages written by other people, like requests for web calls or pandas for data. Install them inside a virtual environment, a private folder of packages for one project, so projects do not disturb each other: python -m venv .venv, then activate it, then pip install requests. Keep a requirements.txt listing what the project needs.
Do this once on your computer and keep your first project in its own folder.
Where to go from here
You now know the core of the language, which is more than most people ever need to start being useful. Choose a direction and build something real in it:
Automation and DevOps: write scripts that rename files, call APIs, parse logs and talk to cloud services. Data and AI: learn pandas, then machine learning libraries. Web: try Flask or FastAPI to build a small website or API. Security and networking: write small tools that check ports and parse packets.
Whatever you pick, the way to improve is the same: build small projects, read other people's code, and fix bugs. Our career paths pages show what to learn for each direction.
Common mistakes
- Writing the whole program before running any of it. Build and run one function at a time.
- Skipping tests because the code looks right. A few asserts take a minute and catch most slips.
- Installing packages globally. Use a virtual environment for each project.
- Copying large chunks from the internet without understanding them. Type it out and change it.
Quick recap
- Split a project into small functions and test each.
- assert is a quick safety net.
- Use python files, pip and a virtual environment on your own computer.
- Pick a direction and build something real.
Practise this week
Work through the 5 exercises for Week 10. Each one tells you which tests pass, and has a hint and a solution if you get stuck.
Check your understanding
Pick an answer for each question, then press Check answers.
This course is for learning. The Python engine runs in your browser and your code is never sent to us.