Skip to content
C

Safe Division Calculator

Easypython

Write a function safe_divide(a, b) that returns the result of a / b, handling ZeroDivisionError by returning the message "Cannot divide by zero" instead of crashing.

What the problem means: wrap a risky operation (division, which can fail if b is 0) in a function that never crashes the caller, no matter what b is.

Approach: put the division inside a try block; catch ZeroDivisionError and return the fallback message instead.

Input: Two lines: a, then b.

Output: One line: the division result, or the message Cannot divide by zero.

Input (stdin)

Output

Run your code to see output here...