Sum 1 to N
Completed
Read n and print the sum 1 + 2 + … + n using a loop and an accumulator variable.
Input
One integer.
Output
The sum.
Example
Input
10
Output
55
Editor
Python
Hints
Start total at 0 before the loop.
Add each i to total inside the loop.
Solution explanation
The accumulator pattern: initialise before the loop, update inside, use after. (sum(range(1, n + 1)) does it in one line.)
Show solution
n = int(input())
total = 0
for i in range(1, n + 1):
total += i
print(total)