Skip to content

Safe division

Python try / except

Same task in: JavaScriptGoPHPRust

Flowchart (ISO 5807)

StartInput a, bReturn a / bEndFigure 1 — safe_div

Source code

Python
def safe_div(a, b):
    try:
        return a / b
    except ZeroDivisionError:
        return 0

The editor opens with this code — change it and the chart redraws.

Language
Python
Constructs
try / except
Topic
Exceptions
Formats
Word, Visio, draw.io, PDF, SVG

Related examples