MODULE 04 · BEGINNER

Functions and reusable programsPython · Module 4

Package clear operations as functions, pass data explicitly, return useful results, and organize code into modules.

8 lessons32 min readingWrite clear Python2 projects
Free, self-paced, and open to everyone. No account needed.
WHAT THIS MODULE COVERS

Functions and reusable programs

Package clear operations as functions, pass data explicitly, return useful results, and organize code into modules.

BEFORE YOU START

Conditions, loops, and collections. You can write working scripts.

WHAT YOU’LL BE ABLE TO DO

Write focused, reusable functions with explicit inputs, meaningful return values, default arguments, and proper module organization without side effects on import.

THE LESSON SEQUENCE

Read in order, or jump to what you need.

Every lesson builds on the one before it. Open any lesson to read the explanation, run the examples, and try the practice challenges.

  1. 04.01
    Defining functions

    Name a useful operation and trace how arguments enter and results leave a function call.

    4 min
  2. 04.02
    Parameters and scope

    Pass arguments clearly, understand local names, and avoid accidental sharing through defaults.

    4 min
  3. 04.03
    Return values and pure functions

    Build predictable transformations with complete return paths and clear boundaries around side effects.

    4 min
  4. 04.04
    Flexible arguments and functional tools

    Design functions that accept variable inputs, pass behavior as a value, and choose readable transformations.

    4 min
  5. 04.05
    Recursion and problem solving

    Solve problems that contain smaller versions of themselves, trace the call stack, and know when iteration is safer.

    4 min
  6. 04.06
    Modules and imports

    Use the standard library and organize your own functions into files that can be imported safely.

    4 min
  7. 04.07
    Project: A number guessing gameProject

    Turn loops, conditions, functions, and input validation into a small game with testable rules.

    4 min
  8. 04.08
    Project: Snake, Water, GunProject

    Build a best-of-five Snake, Water, Gun game with pure rule functions, validated input, and tests that never depend on luck.

    4 min
MODULE SELF-CHECK

Ready to move on?

Separate a calculation logic from input/output display, import your function from a second file, and call it without running unwanted code on import.

Open the module self-check