# File: divby0.py # See what happens when you divide by 0 # # Note: to get to the last two parts (where this catches the exception), # comment out the first division # # Matt Bishop, MHI 289I, Winter 2019 # # # this can be any integer # -- if you want to see the difference between the two catches, # set this to a string like 'hello' x = 7 # # Divide, and bomb y = x / 0 # # Here's how you check for it try: y = x / 0 except: print("Error occurred") # # And here you catch *only* the division by zero or a type error try: y = x / 0 except ZeroDivisionError: print("You can't divide by 0!") print("Really, you can't!") except TypeError: print("You can't divide these types!")