0
0
Pythonprogramming~15 mins

Docstrings and documentation in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Docstrings and Documentation
๐Ÿ“– Scenario: You are creating a small program to help a friend understand how to write clear explanations inside their Python code. This will make the code easier to read and use later.
๐ŸŽฏ Goal: Build a simple Python function with a proper docstring that explains what the function does, its inputs, and its output.
๐Ÿ“‹ What You'll Learn
Create a function named add_numbers that takes two numbers as input
Write a docstring inside the add_numbers function explaining its purpose, parameters, and return value
Call the add_numbers function with two numbers
Print the result of the function call
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Writing clear docstrings helps other programmers understand your code quickly, just like clear instructions help someone use a tool properly.
๐Ÿ’ผ Career
Good documentation is a key skill for software developers, making code easier to maintain and collaborate on in teams.
Progress0 / 4 steps
1
Create the function add_numbers
Write a function named add_numbers that takes two parameters called a and b. Inside the function, return the sum of a and b.
Python
Need a hint?

Use the def keyword to create the function and return to send back the sum.

2
Add a docstring to add_numbers
Inside the add_numbers function, add a docstring that explains:
1. The function adds two numbers.
2. The parameters a and b are numbers.
3. The function returns their sum.
Use triple double quotes """ for the docstring.
Python
Need a hint?

Place the docstring right after the function header, before the return statement.

3
Call the add_numbers function
Call the add_numbers function with the numbers 5 and 7. Store the result in a variable called result.
Python
Need a hint?

Use the function name with parentheses and pass the numbers inside.

4
Print the result
Print the value stored in the variable result.
Python
Need a hint?

Use print(result) to show the output.