Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Divide by 0

  • ZeroDivisionError

  • Another use-case for if and else:


def main():
    a = input('First number: ')
    b = input('Second number: ')

    print("Dividing", a, "by",  b)
    print(int(a) / int(b))
    print("Still running")

main()
First number: 3
Second number: 0
Dividing 3 by 0
Traceback (most recent call last):
  File "examples/basics/divide_by_zero.py", line 9, in <module>
    main()
  File "examples/basics/divide_by_zero.py", line 7, in main
    print(int(a) / int(b))
ZeroDivisionError: division by zero