From ef19351463f4d89122f74334aab38b6ba0f462da Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:55:22 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- flow/examples/README.md | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/flow/examples/README.md b/flow/examples/README.md index 9a15998..5c3cbe9 100644 --- a/flow/examples/README.md +++ b/flow/examples/README.md @@ -111,6 +111,8 @@ while counter < counter_max: {% endraw %} +In Python: + ```python a = int(input()) if a < 1: @@ -121,3 +123,80 @@ else: print("condition else") ``` +## if, elif, else + +{% raw %} +
+ flowchart TD + start([Start]) --> inputa[/"Input integer a"/] --> Condition1{"a < 1"} + Condition1 -- Yes --> Action1[/"print condition 1"/] + Condition1 -- No --> Condition2{"a == 2"} + Condition2 -- Yes --> Action2[/"print condition 2"/] + Condition2 -- No --> ElseAction[/"print condition else"/] + Action1 --> stop([Stop]) + Action2 --> stop + ElseAction --> stop ++{% endraw %} + +In Python: + +```python +a = int(input()) +if a < 1: + print("condition 1") +elif a == 2: + print("condition 2") +else: + print("condition else") +``` + +## functions + +{% raw %} +
+ flowchart TD + Start([Start]) --> Input[/"Input integer a"/] + Input -- a < 1 --> Function1[["function_1()"]] + Function1 --> End([Stop]) + Input -- a == 2 --> Function2[["function_2()"]] --> End + Input -- else --> FunctionElse[["function_else()"]] --> End ++ +
+ flowchart TD + Function1[["function_1()"]] --> Start([Start]) --> Print[/print("condition 1")/] --> End([Stop]) ++ +
+ flowchart TD + Function2[["function_2()"]] --> Start([Start]) --> Print[/print("condition 2")/] --> End([Stop]) ++ +
+ flowchart TD + FunctionElse[["function_else()"]] --> Start([Start]) --> Print[/print("condition else")/] --> End([Stop]) ++ +{% endraw %} + +In Python: + +```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() +```