Module 18: Practice Zone

Let's practice sending values back with the `return` statement!

Spotlight on `return`

Functions can send back results using `return`. Click the highlighted parts of this simple function to see what they do. Notice how this supports Abstraction.

def add_numbers(num1, num2):
   return num1 + num2

Identify all parts!

Predict the Returned Value

When the code below runs, what value will the function calculate_area *return*? Type your answer in the box.

def calculate_area(length, width):
    area = length * width
    return area

result = calculate_area(5, 4)
print(result) # This will print the returned value

Build-a-Function

Drag the pieces below to create a function named greet that takes one parameter name and *returns* the string "Hello, [name]!". This task involves Decomposition.

Drop pieces here to build the function...

Code & Use Return

Write a function called get_initial that takes a name (string) as input and *returns* only the first letter (initial) of the name. Then, call this function with a name (e.g., "Alice") and print the returned initial.

Output will appear here...

Module 18 Practice Complete!

Excellent work practicing with the `return` statement! You're getting better at making functions send back useful information. Ready for more complex challenges? Try the Advanced Practice for Module 18!