Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 12

Increment a Number

Easy

10 minute session

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.

Code editor
Loading editor…

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.

03:41 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.