Function
safe_division
(
number,
divisor,
ignore_overflow,
ignore_zero_division,
)
Source from the content-addressed store, hash-verified
| 49 | |
| 50 | print("Example 1") |
| 51 | def safe_division( |
| 52 | number, |
| 53 | divisor, |
| 54 | ignore_overflow, |
| 55 | ignore_zero_division, |
| 56 | ): |
| 57 | try: |
| 58 | return number / divisor |
| 59 | except OverflowError: |
| 60 | if ignore_overflow: |
| 61 | return 0 |
| 62 | else: |
| 63 | raise |
| 64 | except ZeroDivisionError: |
| 65 | if ignore_zero_division: |
| 66 | return float("inf") |
| 67 | else: |
| 68 | raise |
| 69 | |
| 70 | |
| 71 | print("Example 2") |
Tested by
no test coverage detected