1.5 · Complete guided project

Level 1 · Language basics

1.5Complete guided project

Goal: consolidate all the basics (variables, conditions, loops, functions) in a complete, well-split mini-program.
Estimated time: 20 min · self-paced reading · If you only have 5 min: read “The essentials in 30s” + the diagram.

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.

Common misinterpretation: "I know the syntax, I can program" or "one big messy file is fine". No. Knowing each brick in isolation does not prove you can assemble them: the blank page is beaten by decomposition (pseudo-code, one function per verb). And 80 messy lines cannot be re-read — split into 6 functions with a menu main, they can.
Assembled foundation Verbs, menu, 80 split lines Verbs (functions)One verb = one function+Menu (main)Calling loop, nothing else+80 lines (test)Alone, without copying = acquired Systematic if __name__ == "__main__"; JSON at L2, tests at L3.
Verbs, menu, 80 split lines
Text version of the diagram (SEO / screen readers / translation): 1) Assemble: Nabil uses variables (dicts), conditions (menu), loops (display) and functions (verbs) in a single ~80-line address book. 2) Split: pseudo-code first, one function per verb, main() reduced to the menu loop, protected import. 3) Project: the address book will be persisted in JSON (L2) then tested (L3) — each level reinvests. Lesson: decompose then assemble, and the foundation becomes reflex.

🔎 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

  1. Choose a mini-project: address book (add/search/list/delete), mystery-number game, or looping calculator.
  2. First write the pseudo-code: the big steps in English (draw a number, loop, compare, say higher/lower, count attempts).
  3. Code step by step reusing: one function per step, a while loop to replay, conditions to compare, the random module to draw a number.
  4. Test, trigger errors, fix with print(): take care of the experience (clear messages, displayed attempt count).
You wrote a complete program using all the basics: you no longer just know the syntax, you know how to build.

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.

Section exit checklist
  • 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).
Self-assessment 1-5: can I redo this project alone, without copying?Self-assessment 1-5: does each function have a clear verb and a clean return?

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).

Check your understanding

What does a ~80-line mini-project coded alone prove?

Additional resources (optional, to go further)

Level 1 examFresh, harder questions to test what you've learned