pytutorial/flow/examples
David Rotermund 88614efc3a
Update README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
2023-12-12 16:27:03 +01:00
..
README.md Update README.md 2023-12-12 16:27:03 +01:00

Flowchart examples

{:.no_toc}

* TOC {:toc}

The goal

Looking into some flow chart examples.

Questions to David Rotermund

Most simple program

This program does nothing.

{% raw %}

    flowchart TD
      start([Start])-->stop([Stop])
  

{% endraw %}

In Python:

pass

a+b=c

{% raw %}

    flowchart TD
      start([Start]) --> inita{{"a ← 1"}} --> initb{{"b ← 1"}} --> add("c ← a+b") --> printc[/"print c"/] -->stop([Stop])
  

{% endraw %}

In Python:

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

a+b=c with input from user

{% raw %}

    flowchart TD
      start([Start]) --> inputa[/"Input integer a"/] --> inputb[/"Input integer b"/] --> add("c ← a+b") --> printc[/"print c"/] -->stop([Stop])
  

{% endraw %}

In Python:

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

for-loop / while loop

{% raw %}

    flowchart TD
    start([Start]) --> inita{{"counter ← 0"}} --> inita{{"counter_max ← 100"}} --> Condition{"counter < counter_max"}
    Condition -- Yes --> printcounter[/"print counter"/] --> Action["counter ← counter + 1"]
    Action --> Condition
    Condition -- No --> End(End)
  

{% endraw %}

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