Editor

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.

def is_prime(n):
if n < 2:
return False
for d in range(2, int(n ** 0.5) + 1):
if n % d == 0:
return False
return True
limit = int(input("Check numbers up to: "))
count = 0
for number in range(1, limit + 1):
if is_prime(number):
print(number, "is prime")
count += 1
print("Primes found:", count)
As pseudocode

Drawing...

Downloads have a white background, ready for a document or slides.

Flowchart symbols

SymbolNameUsed forIn Python
TerminalWhere the program or a function starts and endsStart, End, return
ProcessA step that works something out or changes a variabletotal = total + n
Input / outputData coming in from the user or going out to the screeninput(), print()
DecisionA question with two answers: the flow takes one way or the otherif, while, for
Predefined processA call to a function you wrote, which has a chart of its ownshow_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 elif is 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 True has no way out except a break.
  • break and continue: break joins the way out on the right; continue joins 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.