Python code to flowchart
Paste a Python program and see it as a flowchart, one chart for the main program and one for each function.
Drawing...
Flowchart symbols
| Symbol | Name | Used for | In Python |
|---|---|---|---|
| Terminal | Where the program or a function starts and ends | Start, End, return | |
| Process | A step that works something out or changes a variable | total = total + n | |
| Input / output | Data coming in from the user or going out to the screen | input(), print() | |
| Decision | A question with two answers: the flow takes one way or the other | if, while, for | |
| Predefined process | A call to a function you wrote, which has a chart of its own | show_menu() |
How each part of the code is drawn
- if and else: the Yes branch goes down from the diamond and the No branch goes to the right. Each
elifis another diamond on the No side. - for loops: the diamond reads like the loop's first line. "Next item" leads into the loop body, the line on the left goes back for the next pass, and "Done" leaves the loop.
- while loops: the same shape, answered Yes or No.
while Truehas no way out except abreak. - break and continue:
breakjoins the way out on the right;continuejoins the way back on the left. - try and except: the guarded steps sit in a dashed box marked try, followed by a decision for each kind of error.
- Functions: each one has its own chart, starting with its name and parameters. Pick it from the buttons above the chart.
Questions
Does it run my code?
No. It reads the code without running it, so a program that asks for input or loops forever is safe to draw. Run it in the editor to see what it does, or step through it line by line in the code visualizer.
Which parts of Python can it draw?
if, elif and else, for and while loops, break and continue, try and except, with, match, functions and the methods of a class, each function on its own chart. A list comprehension or a lambda stays inside one step, written as code.
Can I use the flowchart in a school project or practical file?
Yes. Download it as PNG or SVG: both have a white background, and the PNG is drawn at twice the size so it stays sharp when printed. SVG opens in Word, Google Docs, PowerPoint and any browser.
Why are some boxes cut short?
A line longer than 70 characters ends with "..." so the chart stays readable. Put a long calculation in a well-named variable or function, and the chart reads better too.
How do I write the algorithm for the same program?
The Python to pseudocode converter writes it as pseudocode, in plain English, Cambridge exam style or as numbered steps.