LEVEL 16: THE RETURN HARVEST 🧺

GETTING RESULTS FROM FUNCTIONS

Until now, our functions have been doing work and printing results directly to the screen. But in real-world programming, functions often need to calculate a value and "hand it back" to the main program to be used later. In Level 16, we introduce the RETURN keyword. At FLORA WORLD CODING, we think of this like sending a robot into a garden to pick a fruit; the robot doesn't just eat the fruit there—it brings it back to you so you can use it in a recipe.

The RETURN statement immediately ends the function and sends the specified value back to the line of code that called it. This is technically different from PRINT(). While PRINT() just shows a message to the human user, RETURN allows you to save the function's output into a variable. For example, MY_RESULT = CALCULATE_SCORE() captures whatever the function produces so you can use it for math or logic later in your script.

Why is this a requirement for professional coding? Because it allows functions to be "pure" and modular. A function that returns a value can be used anywhere: in a web app, a mobile game, or a data analysis tool. It doesn't care how the result is shown; it only cares about calculating the right answer. Mastering return values is a massive step toward understanding how professional software handles complex data pipelines and API responses.

IMPORTANT CODING NOTE: ONCE A FUNCTION HITS A RETURN STATEMENT, IT STOPS COMPLETELY. ANY CODE WRITTEN AFTER THE RETURN LINE INSIDE THE FUNCTION WILL BE IGNORED BY PYTHON!

MASTERY CHALLENGE

CREATE A FUNCTION CALLED MULTIPLY(A, B) THAT RETURNS THE PRODUCT OF THE TWO NUMBERS. OUTSIDE THE FUNCTION, CALL IT AND STORE THE RESULT IN A VARIABLE CALLED TOTAL. FINALLY, PRINT THE TOTAL TO SEE YOUR RETURNED VALUE IN ACTION!

I'M A RETURN SPECIALIST! GO TO LEVEL 17 ➔

← BACK TO LEVEL 15 🏠 HOME