Module 16: Defining Simple Functions

Package code into reusable blocks!

Anatomy of a Function Definition

Functions bundle code. Click each highlighted part of this simple function definition to learn its role. This uses Abstraction to name a task.

def greet(): print("Hello!")

Identify all 5 parts!

Build a Function Call

We defined the `greet()` function above. Now, drag the pieces below to construct the code that *calls* (runs) this function.

Reminder: The function is defined as:

def greet(): print("Hello!")

Construct the function call here:

Drop pieces here...

Define and Call Your Function

Time to write your own! In the editor: 1. Define a function named `say_hello` that prints "Hello from my function!". 2. On a new line *after* the definition, *call* your `say_hello` function. Remember indentation! This uses Abstraction to hide the print detail inside `say_hello`.

Output will appear here...

Spot the Function Call

Which lines below are actually *calling* (running) a function? Click the line(s) that execute a function. This relates to Decomposition - defining tasks and then using them.

Function Mini Missions!

Practice defining and calling. Complete these tasks in the editors below. This shows Decomposition by creating small, focused functions.

Mission 1: Simple Greeting

Define a function named `show_message` that prints "Mission 1 Complete!". Then, call this function.

Mission 2: Two Tasks (Decomposition)

Define two functions: `task_one` (prints "Task One Done.") and `task_two` (prints "Task Two Done."). Then, call *both* functions, one after the other.

Mission 3: Function with Comment

Define a function `ai_greeting` that prints "Greetings, AI Enthusiast!". Add a comment inside the function body explaining what it does. Then, call the function.

Module 16 Practice Complete!

Great job defining and calling functions! You're building reusable code blocks.
Ready for more? Try the Advanced Practice for Module 16!