Safe Divide

Safe Divide

Write a function that divides two numbers.

divide(a, b)

Return a / b. If b is zero, let the natural ZeroDivisionError propagate — don't catch it yourself. The goal here isn't to prevent the error, it's to see what happens when you don't.

Examples

divide(10, 2)   // → 5.0
divide(9, 3)    // → 3.0
divide(10, 0)   // raises ZeroDivisionError

Walkthrough

Thinking it through

There's no clever algorithm here — the whole exercise is noticing what Python already does for you.

a / b is true division in Python 3. When b is 0, Python itself raises ZeroDivisionError: division by zero — you don't have to check for it or raise it manually. If you don't catch it, it propagates straight out of divide and out of whatever called it.

That's exactly the behavior the tests check for: a normal division test expects a numeric answer, and a divide-by-zero test expects the exception to actually escape your function, not get swallowed into a None or a printed message.

This matters because letting an exception propagate is a real, deliberate choice — not just something that happens when you forget to handle it. Sometimes the right answer is "this function shouldn't decide what to do about a zero denominator — the caller should."

main.py
Console
Press Run to execute your code, or Submit to test and complete this problem.