Module 7

Module challenge

Handling errors in practice.

Safe division

Write a function safe_divide(a, b) that returns a / b, but returns 0 if b is zero instead of raising an error.

Your task

Safe division

  • Define safe_divide(a, b) that returns 0 if b is zero.
Remember

• Understand files, folders, and paths • Read and write files conceptually • Use with open(...) • Handle exceptions with try/except • Debug systematically