Which fix removes the bug?
def divide(a, b):
return a / b
print(divide(4, 0))
- Guard against zero b
- Cast both to floats
- Return None on error
- Use // instead of /
Division by zero raises ZeroDivisionError; the caller needs a checked path.
Play Problem Solving ▸