MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / careful_divide

Function careful_divide

example_code/item_032_example_09.py:22–31  ·  view source on GitHub ↗

Divides a by b. Raises: ValueError: When the inputs cannot be divided.

(a: float, b: float)

Source from the content-addressed store, hash-verified

20# Check types in this file with: python3 -m mypy <path>
21
22def careful_divide(a: float, b: float) -> float:
23 """Divides a by b.
24
25 Raises:
26 ValueError: When the inputs cannot be divided.
27 """
28 try:
29 return a / b
30 except ZeroDivisionError:
31 raise ValueError("Invalid inputs")
32
33try:
34 result = careful_divide(1, 0)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected