Introduction to Computer Science/4.5 Formative Skill Drill - "Document a Function"

4.5 Formative Skill Drill - "Document a Function"

🎯 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:

  1. It accepts one parameter: a number.
  2. It calculates the square of that number (the number multiplied by itself).
  3. It returns the calculated result.
  4. 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.

  1. Arrange your Thonny window so that your complete square_number function (including the docstring) is visible, along with the output from your test call.
  2. Take a screenshot of the entire Thonny window.
  3. Submit the screenshot image file here.