Skip to content

Sum 1..n

Python for + range

Flowchart (ISO 5807)

StartInput ns = 0i = 1, n, 1s = s + iReturn sEndFigure 1 — total

Source code

Python
def total(n):
    s = 0
    for i in range(1, n + 1):
        s += i
    return s

The editor opens with this code — change it and the chart redraws.

Language
Python
Constructs
for + range
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples