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.
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.
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.
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.
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!