Problem No 12
Write a function with a simple docstring
Easy≈ 6 minute session
Lesson guide
What this Python exercise practices
Write a function with a simple docstring is a beginner practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Practice path
Summary
Create a small function and include a clear docstring describing its behavior.
Problem statement
Write a function multiply(a, b) that returns the product of a and b. Add a simple docstring to the function exactly: "Multiply two numbers and return the product." Ensure the function behavior matches the docstring and that multiply.__doc__ returns that exact string.
Task
Define a function with an exact docstring and correct behavior so learners practice writing documentation strings.
Examples
Multiply integers
Input
multiply(2, 3)
Output
6
Explanation
2 * 3 equals 6.
Input format
Two numeric values (integers or floats).
Output format
Return the numeric product of the two inputs.
Constraints
Include the exact docstring: "Multiply two numbers and return the product." The function must return a*b.
Samples
Sample input 0
multiply(2.5, 4)
Sample output 0
10.0
Explanation 0
2.5 * 4 equals 10.0.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.