Parameter Power
Functions can accept inputs called parameters. Click the highlighted parts related to the parameter `person_name` to see how it works. This enhances Abstraction.
Identify the 2 parameter-related parts!
Argument Architect
When you *call* a function that expects a parameter, you provide an argument. Drag the pieces to call the `greet_person` function with the argument `"Bob"`.
Reminder: The function is defined as:
Construct the function call with the argument here:
Return Runner
Functions can send back results using the `return` keyword. 1. Define `multiply(x, y)` that returns the product of `x` and `y`. 2. Call it with `4` and `5`, store the result in a variable `product`. 3. Print the `product` variable. This applies Pattern Recognition (multiplication is a pattern).
Code Challenge: Simple Calculator
Combine your skills! Define two functions, `add(a, b)` and `subtract(a, b)`, both returning their results. Then, calculate `10 + 5`, store it, and subtract `3` from that result, printing the final answer. This uses Decomposition (add, subtract) and Abstraction.
Calculator Steps
- Define `add(a, b)` that returns `a + b`.
- Define `subtract(a, b)` that returns `a - b`.
- Call `add` with `10` and `5`, store the result in a variable (e.g., `sum_result`).
- Call `subtract` using `sum_result` and `3`, store the result in another variable (e.g., `final_result`).
- Print the `final_result`.
Module 16 Advanced Practice Complete!
Fantastic! You've mastered passing data into functions and getting results back. This is key for building complex programs.
Check the Video Lesson or head back to the Course Menu.