1.5Complete guided project
The essentials in 30 seconds
- Consolidate = assemble: variables + conditions + loops + functions in a single program — from syntax to know-how-to-build.
- Verbs → functions, menu → main: one verb = one function, main holds only the menu loop that calls.
- 80 lines alone = foundation acquired: pseudo-code first, systematic if __name__ == "__main__", bridge to files (L2) and tests (L3).
Running mini-case — Nabil ships his address book in Algiers
Nabil must ship an address book for his team: add, search, list, delete, quit. He first writes 80 lines in a jumble with the menu copy-pasted five times — and a deletion bug repeats everywhere. He splits it: one verb = one function (add, search, list, delete), a main() with the menu loop, contacts as dictionaries, and if __name__ == "__main__" to protect the import. The address book runs alone, will be saved in JSON at level 2 and tested at level 3: the guide's running thread is launched.
Level capstone — Nabil reinvests 1.1 (variables), 1.2 (menu with conditions), 1.3 (loops) and 1.4 (functions).
1. Assembling the foundation: the address-book mini-project
This chapter is a consolidating breather: variables (contacts as dictionaries), conditions (menu), loops (display and menu loop), functions (add, search, list, delete) — this project assembles all of level 1 in ~80 lines. It is the test: if you code it alone, without copying, explaining each line, the foundation is acquired.
Nabil chooses the address book rather than the mystery-number game: it will serve his team, and each function will be reinvested in later levels.
2. Split before coding, bridge to what's next
List the verbs (add, search, list, delete, quit): one verb = one function. main() holds only the menu loop that calls. Write the pseudo-code in English before coding, protect the import with if __name__ == "__main__". This address book will return at level 2 (files: save as JSON), at level 3 (tests: prove the functions): each level reinvests instead of starting from zero.
Nabil writes his pseudo-code in five lines, codes one function per verb, and already notes "JSON at L2, pytest at L3": the thread runs through the guide.
🔎 Concrete example — 🔎 Concrete example — Address-book skeleton
The structure proving the foundation, like Nabil for his team.
contacts = []
def ajouter(nom, tel):
contacts.append({"nom": nom, "tel": tel})
def chercher(nom):
return [c for c in contacts if c["nom"] == nom]
def lister():
for c in contacts:
print(f"{c['nom']} : {c['tel']}")
def main():
while True:
choix = input("1-add 2-search 3-list 0-quit? ")
if choix == "0":
break
elif choix == "3":
lister()
if __name__ == "__main__":
main()
Reading: the if __name__ protects the future import; the comprehension filters in one line.
Lesson: code first, re-read next — clear messages, trials and displayed cases.
Section vocabulary
- Consolidation
- Re-using several concepts together in one program, until they become reflexes.
Simple example: Nabil's address book mobilizing all four chapters.
What it is not: ten isolated exercises never recombined.
Reflex: one complete project beats ten exercises.
- Running thread
- Follow-up project running through the learning journey, giving each concept meaning by applying it.
Simple example: Nabil's address book, reused in JSON (L2) then in tests (L3).
What it is not: a throwaway project abandoned at each level.
Reflex: reinvest rather than restart from zero.
- Decomposition
- Splitting a problem into small simple steps/functions: the programmer's key skill. One verb = one function.
Simple example: Nabil's add/search/list/delete.
What it is not: writing 80 lines at once facing the blank page.
Reflex: list the verbs before coding.
- Pseudo-code
- Describing a program's steps in plain language before coding it: clarifies logic without syntax.
Simple example: Nabil's five English lines before his address book.
What it is not: coding head-down then debugging for hours.
Reflex: English first, Python next.
- Debugging
- Tracking and fixing errors. print() and reading error messages (read bottom-up) are the first tools.
Simple example: Nabil isolating his deletion bug with prints.
What it is not: changing things randomly until it passes.
Reflex: read the traceback, reproduce, fix, re-check.
In practice — In practice — Assembling the basics: one complete mini-program
- Choose a mini-project: address book (add/search/list/delete), mystery-number game, or looping calculator.
- First write the pseudo-code: the big steps in English (draw a number, loop, compare, say higher/lower, count attempts).
- Code step by step reusing: one function per step, a while loop to replay, conditions to compare, the random module to draw a number.
- Test, trigger errors, fix with print(): take care of the experience (clear messages, displayed attempt count).
Script ready to say — defending the split (30 s)
"I suggest we split into one function per verb, with a main doing only the menu loop: each function is tested in isolation, the bug is located in one read, and we will reuse these functions for the JSON save then the tests."
Say in code review; show the messy file next to the split one.
Copy-paste template — complete address book (L1 capstone)
contacts = []
def ajouter(nom, tel):
contacts.append({"nom": nom, "tel": tel})
return f"{nom} added."
def chercher(nom):
trouves = [c for c in contacts if c["nom"] == nom]
return trouves
def lister():
if not contacts:
return "Address book empty."
return "\n".join(f"{c['nom']} : {c['tel']}" for c in contacts)
def main():
while True:
choix = input("1-add 2-search 3-list 0-quit? ")
if choix == "0":
print("Goodbye!")
break
elif choix == "1":
print(ajouter(input("Name? "), input("Phone? ")))
elif choix == "3":
print(lister())
else:
print("Unknown choice.")
if __name__ == "__main__":
main()
Address book in Algiers
Like Nabil: dicts + verbs + menu main — the team adds and searches with no training, the foundation is proven.
Mystery number
random + while to replay + higher/lower conditions: the same foundation (variables, loops, functions) in a game.
Looping calculator
An operations menu with add/divide functions: division by zero tested in a condition, everything replayable.
L2/L3 bridge
The address book persisted in JSON (L2: with open, json.dump/load) then proven in tests (L3): reinvest, don't restart.
✓ Best practices
- Write the pseudo-code in English before coding.
- One verb = one function, menu = main, protected import.
- Finish one understood project redone alone before level 2.
✗ Common pitfalls
- Writing everything in a jumble with no functions (unreadable at 80 lines).
- Copy-pasting the menu five times instead of one loop.
- Moving to L2 without finishing the address book (fragile foundation).
Key takeaways
- Consolidating = reusing variables, conditions, loops and functions together in a complete program.
- Splitting a problem into small steps is THE skill to develop — pseudo-code first.
- Verbs → functions, menu → main, systematic if __name__ == "__main__".
- One complete mini-project anchors the basics better than ten isolated exercises — and prepares L2 (files) and L3 (tests).
48h challenge — apply tomorrow
Code the address book from the template above alone, without copying: pseudo-code, one function per verb, menu loop, protected import. Add delete(), test each choice, then explain each line out loud. 45 minutes is enough.
- I coded alone a ~80-line program that runs.
- My code is split (verbs → functions, menu → main).
- I can explain each line and aim at L2 (JSON) then L3 (tests).
Frequently asked questions
I know the syntax but I freeze facing a blank page, is that normal?
Very normal, and that is exactly what this chapter is about. The solution is decomposition: don't try to write the whole program at once, split it into tiny steps you already know how to code (pseudo-code), then assemble them one by one.
How many projects should I do before level 2?
One complete, well-understood project beats five rushed ones. If you can redo it alone, without copying, explaining each line, you are ready for level 2. Otherwise, redo a variant (mystery number, calculator).
What does a ~80-line mini-project coded alone prove?