livepython.net
CHAPTER 03Programmer Mindset
3.3  FLOWCHARTS

Flowcharts for Beginners: Shapes, Symbols and Examples

What Is a Flowchart?

A flowchart is a drawing of an algorithm. Each step sits in a shape, and arrows show the order, from top to bottom. Here's the tea recipe as a flowchart:

  1. Start:
    Start
  2. Step:
    Boil water
  3. Step:
    Add tea leaves
  4. Step:
    Add milk and sugar
  5. End:
    End: tea is ready
Making a cup of tea

You can follow it with your finger: start at the top, follow the arrows, stop at the end.

Why draw one?

  • You see the whole plan at once. Problems like a missing step jump out.
  • It's easy to share. Anyone can read a flowchart, even people who don't code.
  • Decisions are clear. When a plan has choices ("is it raining?"), a flowchart shows each path. You'll see that soon.

Flowcharts are optional

Flowcharts and algorithms are thinking tools. You don't have to draw one for every program, and nobody will check! Use them when they help: when a problem feels confusing, when it has several choices, or when you want to explain your plan to someone else.

For small programs, a few steps in plain words are enough. For bigger ones, a quick flowchart on paper can save you a lot of time.

A flowchart is your plan as a drawing: shapes for steps, arrows for order.

your turnPick the right idea

When is a flowchart most helpful?

Think about it, then pick one.

Flowchart Shapes and What They Mean

Flowcharts use a few standard shapes. Each shape tells you what kind of step it is:

ShapeNameMeaningExample
OvalTerminalwhere the flowchart starts or endsStart, End
RectangleProcessan action, a step that does somethingAdd tea leaves
Parallelogram (slanted box)Input / Outputsomething goes in or comes outShow "Hello"
DiamondDecisiona yes-or-no questionIs it raining?
ArrowFlow linewhich step comes next↓

Here they are together:

  1. Start:
    Start
  2. Input or output:
    Show: What's the weather?
  3. Decision:
    Is it raining?
    yes
    Take an umbrella
    no
    Wear sunglasses
  4. Step:
    Go outside
  5. End:
    End
Every basic flowchart shape

How the shapes match Python

You already know one of them in code. Showing something is output, so every print() is a parallelogram in a flowchart. The diamond becomes if in chapter 8, and asking the user for input comes in chapter 7. Learning the shapes now makes those chapters easier.

Simple rules

  • One Start, at the top.
  • Every shape has an arrow out of it, except End.
  • A diamond always has two arrows out: one for Yes, one for No.
  • Keep the words in each shape short.

Oval to start and end, rectangle for steps, parallelogram for input and output, diamond for questions.

your turnPick the right idea

Which shape asks a yes-or-no question?

Think about it, then pick one.

Decisions in a Flowchart

Real plans aren't always a straight line. Sometimes the next step depends on a question. In a flowchart, that's a decision: a diamond with a Yes path and a No path.

  1. Start:
    Start
  2. Step:
    Look out of the window
  3. Decision:
    Is it raining?
    yes
    Take an umbrella
    no
    Leave the umbrella
  4. Step:
    Walk to school
  5. End:
    End
Should I take an umbrella?

Follow it: if it's raining, you take the Yes path. If not, the No path. Either way, both paths meet again, and you walk to school.

Decisions are everywhere

  • A login page: is the password correct? Yes: open the account. No: show an error.
  • A game: did the player reach 100 points? Yes: next level. No: keep playing.
  • A shop: is the item in stock? Yes: sell it. No: show "sold out".

A good question has two clear answers

The question in a diamond must have exactly two answers, Yes or No. "Is it raining?" works. "What's the weather like?" doesn't, because it has many answers. If you need more choices, chain several diamonds, one question each.

Coming soon in Python

In chapter 8 you'll write decisions in code with if and else. A diamond becomes if, the Yes path is the code under it, and the No path goes under else. If you can draw the diamond, you're halfway there.

A diamond asks one yes-or-no question, and the plan splits into two paths.

your turnOrder the lines

Put the login steps in order

  1. End
  2. Is the password correct?
  3. Yes: open the account. No: show an error
  4. Start
  5. Type your password
These lines are mixed up. Put them back in order, then press Check.

From Flowchart to Code

A flowchart without decisions turns into code very easily: read the shapes from top to bottom, and write one line for each step.

  1. Start:
    Start
  2. Input or output:
    Show: Good morning!
  3. Input or output:
    Show: Today is a great day to code.
  4. Input or output:
    Show: Let's begin!
  5. End:
    End
A morning message

Each parallelogram says "show", so each becomes a print():

PYTHONedit me
print("Good morning!")
print("Today is a great day to code.")
print("Let's begin!")
OUTPUT
Good morning!
Today is a great day to code.
Let's begin!

Start and End don't need any code. Python starts at the first line and ends after the last one.

The rules for turning a flowchart into code

  1. Follow the arrows from Start to End.
  2. Write one line of code for each shape, in the same order.
  3. Output shapes (parallelograms) become print().
  4. Check: does your program's output match the flowchart, step by step?

As you learn more Python, more shapes turn into code: input becomes input(), decisions become if, and loops in a flowchart become for and while. The method stays the same.

Follow the arrows, and write one line of code for each shape.

your turnOrder the lines

Turn the morning flowchart into code: put the lines in order

  1. print("Today is a great day to code.")
  2. print("Let's begin!")
  3. print("Good morning!")
These lines are mixed up. Put them back in order, then press Check.

Practice: Flowcharts

Solve these to lock in what you learned in this topic. Each one runs in your browser.

  1. 31.Python Program to Print a Recipe From a FlowchartEasySolve