Skip to content
    Pythonia

    PRACTICAL DEVELOPMENT · 10 MIN

    Building a Real Program

    Combine everything: break a problem into functions, test each piece, then put it together.

    PYRA explains

    • Start with the input and the expected output, then write small functions for each step.
    • Test with tiny examples (assert) before running on real data.
    • Keep code readable: clear names, short functions, and the if __name__ == "__main__": entry point.

    Real world: A to-do app: add tasks, mark them done, count what's left.

    Code

    def add(todos, t):
        return todos + [{"task": t, "done": False}]
    def finish(todos, t):
        return [{**x, "done": True} if x["task"] == t else x for x in todos]
    todos = add(add([], "learn loops"), "build app")
    todos = finish(todos, "learn loops")
    assert len(todos) == 2
    print(sum(not x["done"] for x in todos), "left")
    Output ›
    1 left
    Try it in the online compiler →

    Checkpoint quiz

    What does assert do when its condition is False?