Flowchart examples

The goal

Looking into some flow chart examples.

Questions to David Rotermund

Most simple program

This program does nothing.

Start
Stop

In Python:

pass

a+b=c

Start
a ← 1
b ← 1
c ← a+b
print c
Stop

In Python:

a=1
b=1
c=a+b
print(c)

a+b=c with input from user

Start
Input integer a
Input integer b
c ← a+b
print c
Stop

In Python:

a = int(input())
b = int(input())
c = a + b
print(c)

for-loop / while loop

Yes
No
Start
counter ← 0
counter_max ← 100
counter < counter_max
print counter
counter ← counter + 1
Stop

In Python:

counter_max = 100
for counter in range(0, counter_max):
    print(counter)

or

counter = 0
counter_max = 100
while counter < counter_max:
    print(counter)
    counter += 1

if, elif, else

Yes
No
Yes
No
Start
Input integer a
a < 1
print condition 1
a == 2
print condition 2
print condition else
Stop

In Python:

a = int(input())
if a < 1:
    print("condition 1")
elif a == 2:
    print("condition 2")
else: 
    print("condition else")

if, elif, else

Yes
No
Yes
No
Start
Input integer a
a < 1
print condition 1
a == 2
print condition 2
print condition else
Stop

In Python:

a = int(input())
if a < 1:
    print("condition 1")
elif a == 2:
    print("condition 2")
else: 
    print("condition else")

functions

a < 1
a == 2
else
Start
Input integer a
function_1()
Stop
function_2()
function_else()
function_1()
Start
print condition 1
Stop
function_2()
Start
print condition 2
Stop
function_else()
Start
print condition else
Stop

In Python:

def function_1():
    print("condition 1")

def function_2():
    print("condition 2")

def function_else():
    print("condition else")

a = int(input())
if a < 1:
    function_1()
elif a == 2:
    function_2()
else: 
    function_else()

The source code is Open Source and can be found on GitHub.