Module 4: Data Collections and Functions
Lab: Lab 4.1: Function Fun - Simple Adder
Create a function add_numbers(a, b)
that takes two numbers as parameters and returns their sum. Then, use pre-defined numbers (simulating user input for this sandbox), call your function, and print the result.
Tasks to Complete:
- Define a function named `add_numbers` that accepts two parameters (e.g., `a` and `b`).
- Inside the function, calculate the sum of `a` and `b`.
- Use the `return` statement to send the sum back from the function.
- Two numbers are provided as strings (`num1_val`, `num2_val`). These simulate user input.
- Convert these string values to numerical types (e.g., `float`).
- Call your `add_numbers` function with these converted numbers as arguments.
- Print the value returned by the function in a user-friendly way (e.g., "The sum is: ...").
Python Sandbox
Python execution is powered by Pyodide, running directly in your browser. The `input()` function is not supported in this sandbox; please define variables directly in your code.