Loops and counters

Compute the sum of the whole numbers from 1 up to and including the input number.

Examples

Example 1

Input
3
Expected output
6

Example 2

Input
0
Expected output
0

Hints and solution

Hint 1

Add 1 to the stop value if you use range.

Reveal worked answer

Use range(1, limit + 1) and start with a total of zero. For limit 3 the loop adds 1, then 2, then 3. No iterations are needed for limit 0.

Back to the lesson