Lesson guide
What this Python exercise practices
Add Two Numbers is a beginner practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 8 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Beginner
- Estimated time
- 8 minutes
Practice path
Summary
Learn how to add two numbers together using a simple function.
Problem statement
Create a function `add_numbers` that takes two arguments, `a` and `b`, which are both integers. The function should return the sum of these two integers.
Task
By the end of this lesson, you will be able to write a function that takes two numbers as input and returns their sum.
Examples
Example 1
Input
add_numbers(2, 3)
Output
5
Explanation
The sum of 2 and 3 is 5.
Input format
Two integers, a and b.
Output format
An integer representing the sum of a and b.
Constraints
Both a and b are integers between -1000 and 1000.
Samples
Sample input 0
add_numbers(-1, 1)
Sample output 0
0
Explanation 0
The sum of -1 and 1 is 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 on each of the first 3 lessons in this module.