Lesson guide
What this Python exercise practices
Increment a Number is a beginner practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 10 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Beginner
- Estimated time
- 10 minutes
Related public exercises
Summary
Use augmented assignment to increment a numeric value by a given amount.
Problem statement
Implement increment(n, amount=1) that increases n by amount using augmented assignment (n += amount) and returns the new value. The default increment amount is 1.
Task
Practice using the += operator to update a variable and return the result.
Examples
Increment by 1
Input
increment(3)
Output
4
Explanation
Default amount is 1, so 3 becomes 4.
Input format
A function call increment(n, amount) where n and amount are numbers. amount is optional and defaults to 1.
Output format
Return the updated numeric value after incrementing.
Constraints
n and amount will be integers (can be negative or zero). Use augmented assignment (+=) inside the function.
Samples
Sample input 0
increment(10, 5)
Sample output 0
15
Explanation 0
10 incremented by 5 equals 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.