🎯 Activity Goals
- Immediately apply your knowledge of docstrings to a real function.
- Write a complete function that includes a purpose, parameters, and a return value in its documentation.
Practice Task: Write and Document a Function
Now that you've learned the structure of a professional docstring, it's time to put it into practice. This is a quick "skill drill" to make sure you have the format down cold.
Your Task
Write a complete Python function named square_number that does the following:
- It accepts one parameter: a number.
- It calculates the square of that number (the number multiplied by itself).
- It returns the calculated result.
- Most importantly, it includes a complete, multi-line docstring that describes the function's purpose, its single parameter, and its return value.
You should also include a line of code after your function that calls it and prints the result, so you can test that it works.
Example of how to call it (for testing):
# This code goes OUTSIDE and AFTER your function definition
result = square_number(5)
print(f"The square of 5 is {result}")
How to Submit (Exit Ticket)
For this activity, you will submit a single screenshot.
- Arrange your Thonny window so that your complete
square_numberfunction (including the docstring) is visible, along with the output from your test call. - Take a screenshot of the entire Thonny window.
- Submit the screenshot image file here.