Debian Codegraph @

divide-by-zero-python

raw
1 #!/usr/bin/python3
2
3 # pylint: disable=invalid-name
4 # pylint: enable=invalid-name
5
6 # Copyright (C) 2024, Benjamin Drung <[email protected]>
7 #
8 # Permission to use, copy, modify, and/or distribute this software for any
9 # purpose with or without fee is hereby granted, provided that the above
10 # copyright notice and this permission notice appear in all copies.
11 #
12 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 """try to divide a number by zero and crash"""
21
22
23 def divide_by_zero() -> float:
24 """Be smarter than math and devide 42 by zero."""
25 zero = 0
26 return 42 / zero
27
28
29 def main() -> None:
30 """Try to divide a number by zero and crash."""
31 result = divide_by_zero()
32 print(f"42 / 0 = {result}")
33
34
35 if __name__ == "__main__":
36 main()