Problem No 1
Define a function that adds two numbers
Easy≈ 6 minute session
Lesson guide
What this Python exercise practices
Define a function that adds two numbers 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
Summary
Write a simple function that returns the sum of two numbers.
Problem statement
Implement a function named add that accepts two parameters (a and b) and returns their sum. The function should work with integers and floats. Do not print the result; return it so it can be used by other code.
Task
Create a function add(a, b) that takes two numeric values and returns their sum.
Examples
Add two integers
Input
add(2, 3)
Output
5
Explanation
2 + 3 = 5, so the function returns 5.
Input format
Call the function as add(a, b) where a and b are numbers (int or float).
Output format
Return the numeric sum of a and b.
Constraints
Do not use print. The function should return a value. Handle both integers and floats.
Samples
Sample input 0
add(10, 5)
Sample output 0
15
Explanation 0
10 + 5 = 15
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.